diff options
Diffstat (limited to 'src/google/protobuf/message_lite.cc')
-rw-r--r-- | src/google/protobuf/message_lite.cc | 62 |
1 files changed, 35 insertions, 27 deletions
diff --git a/src/google/protobuf/message_lite.cc b/src/google/protobuf/message_lite.cc index 4f63ad2b..5bd8bcfb 100644 --- a/src/google/protobuf/message_lite.cc +++ b/src/google/protobuf/message_lite.cc @@ -35,7 +35,9 @@ #include <google/protobuf/message_lite.h> #include <google/protobuf/arena.h> +#include <google/protobuf/repeated_field.h> #include <string> +#include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/io/coded_stream.h> #include <google/protobuf/io/zero_copy_stream_impl_lite.h> @@ -98,27 +100,19 @@ string InitializationErrorMessage(const char* action, // call MergePartialFromCodedStream(). However, when parsing very small // messages, every function call introduces significant overhead. To avoid // this without reproducing code, we use these forced-inline helpers. -// -// Note: GCC only allows GOOGLE_ATTRIBUTE_ALWAYS_INLINE on declarations, not -// definitions. +GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InlineMergeFromCodedStream( + io::CodedInputStream* input, MessageLite* message); +GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InlineParseFromCodedStream( + io::CodedInputStream* input, MessageLite* message); +GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InlineParsePartialFromCodedStream( + io::CodedInputStream* input, MessageLite* message); +GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InlineParseFromArray( + const void* data, int size, MessageLite* message); +GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InlineParsePartialFromArray( + const void* data, int size, MessageLite* message); + inline bool InlineMergeFromCodedStream(io::CodedInputStream* input, - MessageLite* message) - GOOGLE_ATTRIBUTE_ALWAYS_INLINE; -inline bool InlineParseFromCodedStream(io::CodedInputStream* input, - MessageLite* message) - GOOGLE_ATTRIBUTE_ALWAYS_INLINE; -inline bool InlineParsePartialFromCodedStream(io::CodedInputStream* input, - MessageLite* message) - GOOGLE_ATTRIBUTE_ALWAYS_INLINE; -inline bool InlineParseFromArray(const void* data, int size, - MessageLite* message) - GOOGLE_ATTRIBUTE_ALWAYS_INLINE; -inline bool InlineParsePartialFromArray(const void* data, int size, - MessageLite* message) - GOOGLE_ATTRIBUTE_ALWAYS_INLINE; - -bool InlineMergeFromCodedStream(io::CodedInputStream* input, - MessageLite* message) { + MessageLite* message) { if (!message->MergePartialFromCodedStream(input)) return false; if (!message->IsInitialized()) { GOOGLE_LOG(ERROR) << InitializationErrorMessage("parse", *message); @@ -127,26 +121,27 @@ bool InlineMergeFromCodedStream(io::CodedInputStream* input, return true; } -bool InlineParseFromCodedStream(io::CodedInputStream* input, - MessageLite* message) { +inline bool InlineParseFromCodedStream(io::CodedInputStream* input, + MessageLite* message) { message->Clear(); return InlineMergeFromCodedStream(input, message); } -bool InlineParsePartialFromCodedStream(io::CodedInputStream* input, - MessageLite* message) { +inline bool InlineParsePartialFromCodedStream(io::CodedInputStream* input, + MessageLite* message) { message->Clear(); return message->MergePartialFromCodedStream(input); } -bool InlineParseFromArray(const void* data, int size, MessageLite* message) { +inline bool InlineParseFromArray( + const void* data, int size, MessageLite* message) { io::CodedInputStream input(reinterpret_cast<const uint8*>(data), size); return InlineParseFromCodedStream(&input, message) && input.ConsumedEntireMessage(); } -bool InlineParsePartialFromArray(const void* data, int size, - MessageLite* message) { +inline bool InlineParsePartialFromArray( + const void* data, int size, MessageLite* message) { io::CodedInputStream input(reinterpret_cast<const uint8*>(data), size); return InlineParsePartialFromCodedStream(&input, message) && input.ConsumedEntireMessage(); @@ -353,5 +348,18 @@ string MessageLite::SerializePartialAsString() const { return output; } +namespace internal { +template<> +MessageLite* GenericTypeHandler<MessageLite>::NewFromPrototype( + const MessageLite* prototype, google::protobuf::Arena* arena) { + return prototype->New(arena); +} +template <> +void GenericTypeHandler<MessageLite>::Merge(const MessageLite& from, + MessageLite* to) { + to->CheckTypeAndMergeFrom(from); +} +} // namespace internal + } // namespace protobuf } // namespace google |