Skip to content

Commit

Permalink
Avoid unnecessary copy in DynamicPatch
Browse files Browse the repository at this point in the history
Summary: For the common? case that a field already exists, avoid copying the value in ensure.

Reviewed By: Mizuchi

Differential Revision: D62673074

fbshipit-source-id: a84799d587115a89f58f05c9f535776f406167b6
  • Loading branch information
Pranav Thulasiram Bhat authored and facebook-github-bot committed Sep 16, 2024
1 parent 4752658 commit 708e316
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,7 @@ void DynamicStructurePatch<IsUnion>::apply(detail::Badge, Object& obj) const {
}
}
void remove(detail::Badge, FieldId id) { obj.erase(id); }
void ensure(detail::Badge, FieldId id, Value v) {
detail::convertStringToBinary(v);

void ensure(detail::Badge, FieldId id, const Value& v) {
if (obj.contains(id)) {
return;
}
Expand All @@ -562,7 +560,9 @@ void DynamicStructurePatch<IsUnion>::apply(detail::Badge, Object& obj) const {
obj.members()->clear();
}

obj[id] = std::move(v);
auto copied = folly::copy(v);
detail::convertStringToBinary(copied);
obj[id] = std::move(copied);
}
Object& obj;
};
Expand Down

0 comments on commit 708e316

Please sign in to comment.