diff --git a/src/google/protobuf/repeated_ptr_field.h b/src/google/protobuf/repeated_ptr_field.h index 8b1b8f193c..64957225e6 100644 --- a/src/google/protobuf/repeated_ptr_field.h +++ b/src/google/protobuf/repeated_ptr_field.h @@ -118,20 +118,20 @@ struct ArenaOffsetHelper { // static int SpaceUsedLong(const Type&); // }; class PROTOBUF_EXPORT RepeatedPtrFieldBase { - template - using Value = typename Handler::Type; + template + using Value = typename TypeHandler::Type; static constexpr int kSSOCapacity = 1; using ElementFactory = void* (*)(Arena*); protected: - // We use the same Handler for all Message types to deduplicate generated + // We use the same TypeHandler for all Message types to deduplicate generated // code. - template + template using CommonHandler = typename std::conditional< - std::is_base_of>::value, - internal::GenericTypeHandler, Handler>::type; + std::is_base_of>::value, + GenericTypeHandler, TypeHandler>::type; constexpr RepeatedPtrFieldBase() : tagged_rep_or_elem_(nullptr), @@ -186,12 +186,12 @@ class PROTOBUF_EXPORT RepeatedPtrFieldBase { return cast(element_at(index)); } - template - Value* Add() { - if (std::is_same, std::string>{}) { - return cast(AddString()); + template + Value* Add() { + if (std::is_same, std::string>{}) { + return cast(AddString()); } - return cast(AddMessageLite(Handler::GetNewFunc())); + return cast(AddMessageLite(TypeHandler::GetNewFunc())); } template < @@ -771,8 +771,8 @@ void RepeatedPtrFieldBase::MergeFrom( const RepeatedPtrFieldBase& from); -template -void* RepeatedPtrFieldBase::AddInternal(F factory) { +template +void* RepeatedPtrFieldBase::AddInternal(Factory factory) { Arena* const arena = GetArena(); if (tagged_rep_or_elem_ == nullptr) { ExchangeCurrentSize(1); @@ -813,29 +813,29 @@ template class GenericTypeHandler { public: using Type = GenericType; - using Movable = IsMovable; + using Movable = IsMovable; static constexpr auto GetNewFunc() { return Arena::DefaultConstruct; } - static inline Arena* GetArena(GenericType* value) { + static inline Arena* GetArena(Type* value) { return Arena::InternalGetArena(value); } - static inline GenericType* New(Arena* arena) { - return static_cast(Arena::DefaultConstruct(arena)); + static inline Type* New(Arena* arena) { + return static_cast(Arena::DefaultConstruct(arena)); } - static inline GenericType* New(Arena* arena, GenericType&& value) { - return Arena::Create(arena, std::move(value)); + static inline Type* New(Arena* arena, Type&& value) { + return Arena::Create(arena, std::move(value)); } - static inline GenericType* NewFromPrototype(const GenericType* /*prototype*/, - Arena* arena = nullptr) { + static inline Type* NewFromPrototype(const Type* /*prototype*/, + Arena* arena = nullptr) { return New(arena); } - static inline void Delete(GenericType* value, Arena* arena) { + static inline void Delete(Type* value, Arena* arena) { if (arena != nullptr) return; #ifdef __cpp_if_constexpr - if constexpr (std::is_base_of::value) { + if constexpr (std::is_base_of::value) { // Using virtual destructor to reduce generated code size that would have - // happened otherwise due to inlined `~GenericType`. + // happened otherwise due to inlined `~Type()`. InternalOutOfLineDeleteMessageLite(value); } else { delete value; @@ -844,9 +844,9 @@ class GenericTypeHandler { delete value; #endif } - static inline void Clear(GenericType* value) { value->Clear(); } - static void Merge(const GenericType& from, GenericType* to); - static inline size_t SpaceUsedLong(const GenericType& value) { + static inline void Clear(Type* value) { value->Clear(); } + static void Merge(const Type& from, Type* to); + static inline size_t SpaceUsedLong(const Type& value) { return value.SpaceUsedLong(); } }; @@ -894,28 +894,25 @@ class GenericTypeHandler { using Movable = IsMovable; static constexpr auto GetNewFunc() { return NewStringElement; } - static inline Arena* GetArena(std::string*) { return nullptr; } + static inline Arena* GetArena(Type*) { return nullptr; } - static PROTOBUF_NOINLINE std::string* New(Arena* arena) { - return Arena::Create(arena); + static PROTOBUF_NOINLINE Type* New(Arena* arena) { + return Arena::Create(arena); } - static PROTOBUF_NOINLINE std::string* New(Arena* arena, std::string&& value) { - return Arena::Create(arena, std::move(value)); + static PROTOBUF_NOINLINE Type* New(Arena* arena, Type&& value) { + return Arena::Create(arena, std::move(value)); } - static inline std::string* NewFromPrototype(const std::string*, - Arena* arena) { + static inline Type* NewFromPrototype(const Type*, Arena* arena) { return New(arena); } - static inline void Delete(std::string* value, Arena* arena) { + static inline void Delete(Type* value, Arena* arena) { if (arena == nullptr) { delete value; } } - static inline void Clear(std::string* value) { value->clear(); } - static inline void Merge(const std::string& from, std::string* to) { - *to = from; - } - static size_t SpaceUsedLong(const std::string& value) { + static inline void Clear(Type* value) { value->clear(); } + static inline void Merge(const Type& from, Type* to) { *to = from; } + static size_t SpaceUsedLong(const Type& value) { return sizeof(value) + StringSpaceUsedExcludingSelfLong(value); } };