diff --git a/thrift/lib/cpp2/op/detail/ValuePatch.h b/thrift/lib/cpp2/op/detail/ValuePatch.h index 8c530935c07..2b03cc9b77c 100644 --- a/thrift/lib/cpp2/op/detail/ValuePatch.h +++ b/thrift/lib/cpp2/op/detail/ValuePatch.h @@ -370,23 +370,25 @@ class BinaryPatch : public BaseStringPatch> { using Base = BaseStringPatch; using T = typename Base::value_type; - public: - using Base::apply; - using Base::assign; - using Base::Base; - - void assign(std::string s) { + static folly::IOBuf stringToIobuf(std::string s) { std::string* p = new std::string(std::move(s)); - assign(folly::IOBuf( + return folly::IOBuf( folly::IOBuf::TAKE_OWNERSHIP, p->data(), p->size(), [](void*, void* userData) { delete static_cast(userData); }, - static_cast(p))); + static_cast(p)); } + public: + using Base::apply; + using Base::assign; + using Base::Base; + + void assign(std::string s) { assign(stringToIobuf(std::move(s))); } + template BinaryPatch& operator=(T&& other) { return assign(std::forward(other)), *this; @@ -433,7 +435,7 @@ class BinaryPatch : public BaseStringPatch> { } void apply(std::string& val) const { - folly::IOBuf buf; + folly::IOBuf buf = stringToIobuf(std::move(val)); apply(buf); val = buf.to(); }