Skip to content

Commit 2ae6d70

Browse files
thedavekwonfacebook-github-bot
authored andcommitted
Change DynamicPatch removeMulti to pass by value
Summary: TSIA Reviewed By: iahs Differential Revision: D71639094 fbshipit-source-id: 81e17a07a69f21a05ddff50f41cab22b0dd56e77
1 parent 51e1bcd commit 2ae6d70

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

thrift/lib/thrift/detail/DynamicPatch.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@ void DynamicUnknownPatch::throwIncompatibleCategory(
15291529
method,
15301530
debugStringViaEncode(patch_)));
15311531
}
1532-
void DynamicUnknownPatch::removeMulti(const detail::ValueSet& v) {
1532+
void DynamicUnknownPatch::removeMulti(detail::ValueSet v) {
15331533
if (!isOneOfCategory(
15341534
{Category::EmptyPatch,
15351535
Category::ClearPatch,
@@ -1538,9 +1538,7 @@ void DynamicUnknownPatch::removeMulti(const detail::ValueSet& v) {
15381538
}
15391539

15401540
auto& s = get(op::PatchOp::Remove).ensure_set();
1541-
for (const auto& k : v) {
1542-
s.insert(k);
1543-
}
1541+
v.eraseInto(v.begin(), v.end(), [&](auto&& k) { s.insert(std::move(k)); });
15441542
}
15451543
void DynamicUnknownPatch::assign(Object v) {
15461544
if (!isOneOfCategory(

thrift/lib/thrift/detail/DynamicPatch.h

+9-10
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class DynamicPatchBase {
182182
class DynamicUnknownPatch : public DynamicPatchBase {
183183
public:
184184
void assign(Object v);
185-
void removeMulti(const detail::ValueSet& v);
185+
void removeMulti(detail::ValueSet v);
186186
void patchIfSet(FieldId, const DynamicPatch&);
187187

188188
void fromObject(detail::Badge badge, Object obj) {
@@ -338,10 +338,10 @@ class DynamicSetPatch : public DynamicPatchBase {
338338
}
339339
}
340340

341-
void removeMulti(detail::Badge badge, const detail::ValueSet& remove) {
342-
for (const auto& i : remove) {
343-
erase(badge, i);
344-
}
341+
void removeMulti(detail::Badge badge, detail::ValueSet remove) {
342+
remove.eraseInto(remove.begin(), remove.end(), [&](auto&& k) {
343+
erase(badge, std::move(k));
344+
});
345345
}
346346

347347
private:
@@ -416,10 +416,8 @@ class DynamicMapPatch {
416416
void erase(Value k);
417417

418418
void tryPutMulti(detail::ValueMap v);
419-
void removeMulti(const detail::ValueSet& v) {
420-
for (const auto& k : v) {
421-
erase(k);
422-
}
419+
void removeMulti(detail::ValueSet v) {
420+
v.eraseInto(v.begin(), v.end(), [&](auto&& k) { erase(std::move(k)); });
423421
}
424422
void putMulti(detail::ValueMap m) {
425423
detail::checkHomogeneousContainer(m);
@@ -880,7 +878,8 @@ void DynamicUnknownPatch::customVisitImpl(Self&& self, Visitor&& v) {
880878
}
881879

882880
if (auto remove = self.get_ptr(op::PatchOp::Remove)) {
883-
std::forward<Visitor>(v).removeMulti(remove->as_set());
881+
std::forward<Visitor>(v).removeMulti(
882+
folly::forward_like<Self>(remove->as_set()));
884883
}
885884
}
886885

0 commit comments

Comments
 (0)