From 4e229c8b5c62a3cd39196b71cbf1da6158335d5e Mon Sep 17 00:00:00 2001 From: Camillo Lugaresi Date: Tue, 20 Dec 2016 17:38:09 -0800 Subject: add MethodResultCallback_0_0 --- src/google/protobuf/stubs/callback.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/google/protobuf/stubs/callback.h b/src/google/protobuf/stubs/callback.h index bbd507a8..9ec04979 100644 --- a/src/google/protobuf/stubs/callback.h +++ b/src/google/protobuf/stubs/callback.h @@ -346,6 +346,29 @@ struct InternalConstRef { typedef const base_type& type; }; +template +class MethodResultCallback_0_0 : public ResultCallback { + public: + typedef R (T::*MethodType)(); + MethodResultCallback_0_0(T* object, MethodType method, bool self_deleting) + : object_(object), + method_(method), + self_deleting_(self_deleting) {} + ~MethodResultCallback_0_0() {} + + R Run() { + bool needs_delete = self_deleting_; + R result = (object_->*method_)(); + if (needs_delete) delete this; + return result; + } + + private: + T* object_; + MethodType method_; + bool self_deleting_; +}; + template class MethodResultCallback_5_2 : public ResultCallback2 { @@ -520,6 +543,13 @@ inline ResultCallback1* NewPermanentCallback( function, false, p1); } +// See MethodResultCallback_0_0 +template +inline ResultCallback* NewPermanentCallback( + T1* object, R (T2::*function)()) { + return new internal::MethodResultCallback_0_0(object, function, false); +} + // See MethodResultCallback_5_2 template -- cgit v1.2.3 From abe172564edfdca186188e1a76924aa1a88eb65f Mon Sep 17 00:00:00 2001 From: Camillo Lugaresi Date: Tue, 20 Dec 2016 17:39:37 -0800 Subject: simpler, cheaper callback to LazyStringOutputStream --- src/google/protobuf/compiler/cpp/cpp_message.cc | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc index 2b71acb5..2d3d5640 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -1661,18 +1661,6 @@ void MessageGenerator:: GenerateClassMethods(io::Printer* printer) { if (IsMapEntryMessage(descriptor_)) return; - // mutable_unknown_fields wrapper function for LazyStringOutputStream - // callback. - if (PreserveUnknownFields(descriptor_) && - !UseUnknownFieldSet(descriptor_->file(), options_)) { - printer->Print( - "static ::std::string* MutableUnknownFieldsFor$classname$(\n" - " $classname$* ptr) {\n" - " return ptr->mutable_unknown_fields();\n" - "}\n" - "\n", - "classname", classname_); - } if (IsAnyMessage(descriptor_)) { printer->Print( "void $classname$::PackFrom(const ::google::protobuf::Message& message) {\n" @@ -2936,8 +2924,8 @@ GenerateMergeFromCodedStream(io::Printer* printer) { // on the CodedOutputStream. printer->Print( " ::google::protobuf::io::LazyStringOutputStream unknown_fields_string(\n" - " NewPermanentCallback(\n" - " &MutableUnknownFieldsFor$classname$, this));\n" + " ::google::protobuf::NewPermanentCallback(&_internal_metadata_,\n" + " &::google::protobuf::internal::InternalMetadataWithArenaLite::mutable_unknown_fields));\n" " ::google::protobuf::io::CodedOutputStream unknown_fields_stream(\n" " &unknown_fields_string, false);\n", "classname", classname_); -- cgit v1.2.3