diff options
Diffstat (limited to 'src/google/protobuf/map_type_handler.h')
-rw-r--r-- | src/google/protobuf/map_type_handler.h | 186 |
1 files changed, 99 insertions, 87 deletions
diff --git a/src/google/protobuf/map_type_handler.h b/src/google/protobuf/map_type_handler.h index f8ad7584..7f7b1e0e 100644 --- a/src/google/protobuf/map_type_handler.h +++ b/src/google/protobuf/map_type_handler.h @@ -32,7 +32,6 @@ #define GOOGLE_PROTOBUF_TYPE_HANDLER_H__ #include <google/protobuf/arena.h> -#include <google/protobuf/generated_message_util.h> #include <google/protobuf/wire_format_lite_inl.h> namespace google { @@ -73,7 +72,7 @@ class MapValueInitializer<true, Type> { template <typename Type> class MapValueInitializer<false, Type> { public: - static inline void Initialize(Type& value, int default_enum_value) {} + static inline void Initialize(Type& /* value */, int /* default_enum_value */) {} }; template <typename Type, bool is_arena_constructable> @@ -158,15 +157,18 @@ class MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type> { MapWireFieldTypeTraits<WireFormatLite::TYPE_MESSAGE, Type>::kIsEnum; // Functions used in parsing and serialization. =================== - static inline int ByteSize(const MapEntryAccessorType& value); + static inline size_t ByteSize(const MapEntryAccessorType& value); static inline int GetCachedSize(const MapEntryAccessorType& value); static inline bool Read(io::CodedInputStream* input, MapEntryAccessorType* value); static inline void Write(int field, const MapEntryAccessorType& value, io::CodedOutputStream* output); + static inline uint8* InternalWriteToArray(int field, + const MapEntryAccessorType& value, + bool deterministic, uint8* target); static inline uint8* WriteToArray(int field, const MapEntryAccessorType& value, - uint8* output); + uint8* target); // Functions to manipulate data on memory. ======================== static inline const Type& GetExternalReference(const Type* value); @@ -183,9 +185,9 @@ class MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type> { static inline Type* EnsureMutable(Type** value, Arena* arena); // SpaceUsedInMapEntry: Return bytes used by value in MapEntry, excluding // those already calculate in sizeof(MapField). - static inline int SpaceUsedInMapEntry(const Type* value); + static inline size_t SpaceUsedInMapEntryLong(const Type* value); // Return bytes used by value in Map. - static inline int SpaceUsedInMap(const Type& value); + static inline size_t SpaceUsedInMapLong(const Type& value); // Assign default value to given instance. static inline void AssignDefaultValue(Type** value); // Return default instance if value is not initialized when calling const @@ -220,9 +222,14 @@ class MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type> { MapEntryAccessorType* value); \ static inline void Write(int field, const MapEntryAccessorType& value, \ io::CodedOutputStream* output); \ + static inline uint8* InternalWriteToArray( \ + int field, const MapEntryAccessorType& value, bool deterministic, \ + uint8* target); \ static inline uint8* WriteToArray(int field, \ const MapEntryAccessorType& value, \ - uint8* output); \ + uint8* target) { \ + return InternalWriteToArray(field, value, false, target); \ + } \ static inline const MapEntryAccessorType& GetExternalReference( \ const TypeOnMemory& value); \ static inline void DeleteNoArena(const TypeOnMemory& x); \ @@ -232,9 +239,9 @@ class MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type> { static inline void ClearMaybeByDefaultEnum(TypeOnMemory* value, \ Arena* arena, \ int default_enum); \ - static inline int SpaceUsedInMapEntry(const TypeOnMemory& value); \ - static inline int SpaceUsedInMap(const TypeOnMemory& value); \ - static inline int SpaceUsedInMap(const string& value); \ + static inline size_t SpaceUsedInMapEntryLong(const TypeOnMemory& value); \ + static inline size_t SpaceUsedInMapLong(const TypeOnMemory& value); \ + static inline size_t SpaceUsedInMapLong(const string& value); \ static inline void AssignDefaultValue(TypeOnMemory* value); \ static inline const MapEntryAccessorType& DefaultIfNotInitialized( \ const TypeOnMemory& value, const TypeOnMemory& default_value); \ @@ -266,7 +273,7 @@ MAP_HANDLER(BOOL) #undef MAP_HANDLER template <typename Type> -inline int +inline size_t MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::ByteSize( const MapEntryAccessorType& value) { return WireFormatLite::MessageSizeNoVirtual(value); @@ -276,7 +283,7 @@ MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::ByteSize( template <typename Type> \ inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::ByteSize( \ const MapEntryAccessorType& value) { \ - return WireFormatLite::DeclaredType##Size(value); \ + return static_cast<int>(WireFormatLite::DeclaredType##Size(value)); \ } GOOGLE_PROTOBUF_BYTE_SIZE(STRING, String) @@ -294,7 +301,7 @@ GOOGLE_PROTOBUF_BYTE_SIZE(ENUM , Enum) #define FIXED_BYTE_SIZE(FieldType, DeclaredType) \ template <typename Type> \ inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::ByteSize( \ - const MapEntryAccessorType& value) { \ + const MapEntryAccessorType& /* value */) { \ return WireFormatLite::k##DeclaredType##Size; \ } @@ -312,7 +319,9 @@ template <typename Type> inline int MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::GetCachedSize( const MapEntryAccessorType& value) { - return WireFormatLite::LengthDelimitedSize(value.GetCachedSize()); + return static_cast<int>( + WireFormatLite::LengthDelimitedSize( + static_cast<size_t>(value.GetCachedSize()))); } #define GET_CACHED_SIZE(FieldType, DeclaredType) \ @@ -320,7 +329,7 @@ MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::GetCachedSize( inline int \ MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::GetCachedSize( \ const MapEntryAccessorType& value) { \ - return WireFormatLite::DeclaredType##Size(value); \ + return static_cast<int>(WireFormatLite::DeclaredType##Size(value)); \ } GET_CACHED_SIZE(STRING, String) @@ -339,7 +348,7 @@ GET_CACHED_SIZE(ENUM , Enum) template <typename Type> \ inline int \ MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::GetCachedSize( \ - const MapEntryAccessorType& value) { \ + const MapEntryAccessorType& /* value */) { \ return WireFormatLite::k##DeclaredType##Size; \ } @@ -362,9 +371,11 @@ inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::Write( template <typename Type> inline uint8* -MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::WriteToArray( - int field, const MapEntryAccessorType& value, uint8* output) { - return WireFormatLite::WriteMessageToArray(field, value, output); +MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::InternalWriteToArray( + int field, const MapEntryAccessorType& value, bool deterministic, + uint8* target) { + return WireFormatLite::InternalWriteMessageToArray(field, value, + deterministic, target); } #define WRITE_METHOD(FieldType, DeclaredType) \ @@ -376,9 +387,10 @@ MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::WriteToArray( } \ template <typename Type> \ inline uint8* \ - MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::WriteToArray( \ - int field, const MapEntryAccessorType& value, uint8* output) { \ - return WireFormatLite::Write##DeclaredType##ToArray(field, value, output); \ + MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ + Type>::InternalWriteToArray( \ + int field, const MapEntryAccessorType& value, bool, uint8* target) { \ + return WireFormatLite::Write##DeclaredType##ToArray(field, value, target); \ } WRITE_METHOD(STRING , String) @@ -454,34 +466,33 @@ MapTypeHandler<WireFormatLite::TYPE_MESSAGE, } template <typename Type> -inline int -MapTypeHandler<WireFormatLite::TYPE_MESSAGE, - Type>::SpaceUsedInMapEntry(const Type* value) { - return value->SpaceUsed(); +inline size_t MapTypeHandler<WireFormatLite::TYPE_MESSAGE, + Type>::SpaceUsedInMapEntryLong(const Type* value) { + return value->SpaceUsedLong(); } template <typename Type> -int MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::SpaceUsedInMap( +size_t MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::SpaceUsedInMapLong( const Type& value) { - return value.SpaceUsed(); + return value.SpaceUsedLong(); } template <typename Type> inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::Clear( - Type** value, Arena* arena) { + Type** value, Arena* /* arena */) { if (*value != NULL) (*value)->Clear(); } template <typename Type> inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::ClearMaybeByDefaultEnum(Type** value, - Arena* arena, - int default_enum_value) { + Arena* /* arena */, + int /* default_enum_value */) { if (*value != NULL) (*value)->Clear(); } template <typename Type> inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::Merge( - const Type& from, Type** to, Arena* arena) { + const Type& from, Type** to, Arena* /* arena */) { (*to)->MergeFrom(from); } @@ -494,20 +505,20 @@ void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::DeleteNoArena( template <typename Type> inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::AssignDefaultValue(Type** value) { - *value = const_cast<Type*>(&Type::default_instance()); + *value = const_cast<Type*>(Type::internal_default_instance()); } template <typename Type> inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::Initialize(Type** x, - Arena* arena) { + Arena* /* arena */) { *x = NULL; } template <typename Type> inline void MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>:: - InitializeMaybeByDefaultEnum(Type** x, int default_enum_value, - Arena* arena) { + InitializeMaybeByDefaultEnum(Type** x, int /* default_enum_value */, + Arena* /* arena */) { *x = NULL; } @@ -543,62 +554,63 @@ inline bool MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::MapEntryAccessorType& \ MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ Type>::GetExternalReference(const TypeOnMemory& value) { \ - return value.Get(&::google::protobuf::internal::GetEmptyString()); \ + return value.Get(); \ } \ template <typename Type> \ - inline int \ - MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::SpaceUsedInMapEntry( \ - const TypeOnMemory& value) { \ + inline size_t \ + MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ + Type>::SpaceUsedInMapEntryLong(const TypeOnMemory& value) { \ return sizeof(value); \ } \ template <typename Type> \ - inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ - Type>::SpaceUsedInMap(const TypeOnMemory& value) { \ + inline size_t \ + MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::SpaceUsedInMapLong( \ + const TypeOnMemory& value) { \ return sizeof(value); \ } \ template <typename Type> \ - inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ - Type>::SpaceUsedInMap(const string& value) { \ + inline size_t \ + MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::SpaceUsedInMapLong( \ + const string& value) { \ return sizeof(value); \ } \ template <typename Type> \ inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Clear( \ TypeOnMemory* value, Arena* arena) { \ - value->ClearToEmpty(&::google::protobuf::internal::GetEmptyString(), arena); \ + value->ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), \ + arena); \ } \ template <typename Type> \ - inline void \ - MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ - Type>::ClearMaybeByDefaultEnum(TypeOnMemory* value, \ - Arena* arena, \ - int default_enum) { \ + inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>:: \ + ClearMaybeByDefaultEnum(TypeOnMemory* value, Arena* arena, \ + int /* default_enum */) { \ Clear(value, arena); \ } \ template <typename Type> \ inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Merge( \ const MapEntryAccessorType& from, TypeOnMemory* to, Arena* arena) { \ - to->Set(&::google::protobuf::internal::GetEmptyString(), from, arena); \ + to->Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from, arena); \ } \ template <typename Type> \ void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::DeleteNoArena( \ TypeOnMemory& value) { \ - value.DestroyNoArena(&::google::protobuf::internal::GetEmptyString()); \ + value.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); \ } \ template <typename Type> \ inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ - Type>::AssignDefaultValue(TypeOnMemory* value) {} \ + Type>::AssignDefaultValue(TypeOnMemory* /* value */) {} \ template <typename Type> \ inline void \ MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Initialize( \ - TypeOnMemory* value, Arena* arena) { \ - value->UnsafeSetDefault(&::google::protobuf::internal::GetEmptyString()); \ + TypeOnMemory* value, Arena* /* arena */) { \ + value->UnsafeSetDefault( \ + &::google::protobuf::internal::GetEmptyStringAlreadyInited()); \ } \ template <typename Type> \ - inline void \ - MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ - Type>::InitializeMaybeByDefaultEnum(TypeOnMemory* value, \ - int default_enum_value, \ - Arena* arena) { \ + inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>:: \ + InitializeMaybeByDefaultEnum(TypeOnMemory* value, \ + int /* default_enum_value */, \ + Arena* arena) { \ Initialize(value, arena); \ } \ template <typename Type> \ @@ -606,7 +618,8 @@ inline bool MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::MapEntryAccessorType* \ MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::EnsureMutable( \ TypeOnMemory* value, Arena* arena) { \ - return value->Mutable(&::google::protobuf::internal::GetEmptyString(), arena); \ + return value->Mutable(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), \ + arena); \ } \ template <typename Type> \ inline const typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ @@ -614,12 +627,12 @@ inline bool MapTypeHandler<WireFormatLite::TYPE_MESSAGE, MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ Type>::DefaultIfNotInitialized(const TypeOnMemory& value, \ const TypeOnMemory& \ - default_value) { \ - return value.Get(&::google::protobuf::internal::GetEmptyString()); \ + /* default_value */) { \ + return value.Get(); \ } \ template <typename Type> \ inline bool MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ - Type>::IsInitialized(const TypeOnMemory& value) { \ + Type>::IsInitialized(const TypeOnMemory& /* value */) { \ return true; \ } STRING_OR_BYTES_HANDLER_FUNCTIONS(STRING) @@ -635,59 +648,58 @@ STRING_OR_BYTES_HANDLER_FUNCTIONS(BYTES) return value; \ } \ template <typename Type> \ - inline int \ - MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::SpaceUsedInMapEntry( \ - const TypeOnMemory& value) { \ + inline size_t \ + MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ + Type>::SpaceUsedInMapEntryLong(const TypeOnMemory& /* value */) { \ return 0; \ } \ template <typename Type> \ - inline int MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ - Type>::SpaceUsedInMap(const TypeOnMemory& value) { \ + inline size_t \ + MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::SpaceUsedInMapLong( \ + const TypeOnMemory& /* value */) { \ return sizeof(Type); \ } \ template <typename Type> \ inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Clear( \ - TypeOnMemory* value, Arena* arena) { \ + TypeOnMemory* value, Arena* /* arena */) { \ *value = 0; \ } \ template <typename Type> \ - inline void \ - MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ - Type>::ClearMaybeByDefaultEnum(TypeOnMemory* value, \ - Arena* arena, \ - int default_enum_value) { \ + inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>:: \ + ClearMaybeByDefaultEnum(TypeOnMemory* value, Arena* /* arena */, \ + int default_enum_value) { \ *value = static_cast<TypeOnMemory>(default_enum_value); \ } \ template <typename Type> \ inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Merge( \ - const MapEntryAccessorType& from, TypeOnMemory* to, Arena* arena) { \ + const MapEntryAccessorType& from, TypeOnMemory* to, \ + Arena* /* arena */) { \ *to = from; \ } \ template <typename Type> \ inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ - Type>::DeleteNoArena(TypeOnMemory& x) {} \ + Type>::DeleteNoArena(TypeOnMemory& /* x */) {} \ template <typename Type> \ inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ - Type>::AssignDefaultValue(TypeOnMemory* value) {} \ + Type>::AssignDefaultValue(TypeOnMemory* /* value */) {} \ template <typename Type> \ inline void \ MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::Initialize( \ - TypeOnMemory* value, Arena* arena) { \ + TypeOnMemory* value, Arena* /* arena */) { \ *value = 0; \ } \ template <typename Type> \ - inline void \ - MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ - Type>::InitializeMaybeByDefaultEnum(TypeOnMemory* value, \ - int default_enum_value, \ - Arena* arena) { \ + inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>:: \ + InitializeMaybeByDefaultEnum(TypeOnMemory* value, \ + int default_enum_value, \ + Arena* /* arena */) { \ *value = static_cast<TypeOnMemory>(default_enum_value); \ } \ template <typename Type> \ inline typename MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ Type>::MapEntryAccessorType* \ MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>::EnsureMutable( \ - TypeOnMemory* value, Arena* arena) { \ + TypeOnMemory* value, Arena* /* arena */) { \ return value; \ } \ template <typename Type> \ @@ -696,12 +708,12 @@ STRING_OR_BYTES_HANDLER_FUNCTIONS(BYTES) MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ Type>::DefaultIfNotInitialized(const TypeOnMemory& value, \ const TypeOnMemory& \ - default_value) { \ + /* default_value */) { \ return value; \ } \ template <typename Type> \ inline bool MapTypeHandler<WireFormatLite::TYPE_##FieldType, \ - Type>::IsInitialized(const TypeOnMemory& value) { \ + Type>::IsInitialized(const TypeOnMemory& /* value */) { \ return true; \ } PRIMITIVE_HANDLER_FUNCTIONS(INT64) |