diff --git a/src/google/protobuf/serial_arena.h b/src/google/protobuf/serial_arena.h index 79ae025b2f..77d1ac413e 100644 --- a/src/google/protobuf/serial_arena.h +++ b/src/google/protobuf/serial_arena.h @@ -251,25 +251,12 @@ class PROTOBUF_EXPORT SerialArena { return true; } - // If there is enough space in the current block, allocate space for one `T` - // object and register for destruction. The object has not been constructed - // and the memory returned is uninitialized. - template - PROTOBUF_ALWAYS_INLINE void* MaybeAllocateWithCleanup() { - ABSL_DCHECK_GE(limit_, ptr()); - static_assert(!std::is_trivially_destructible::value, - "This function is only for non-trivial types."); - - constexpr int aligned_size = ArenaAlignDefault::Ceil(sizeof(T)); - constexpr auto destructor = cleanup::arena_destruct_object; - size_t required = aligned_size + cleanup::Size(destructor); - if (PROTOBUF_PREDICT_FALSE(!HasSpace(required))) { - return nullptr; - } - void* ptr = AllocateFromExistingWithCleanupFallback(aligned_size, - alignof(T), destructor); - PROTOBUF_ASSUME(ptr != nullptr); - return ptr; + // If there is enough space in the current block, allocate space for one + // std::string object and register for destruction. The object has not been + // constructed and the memory returned is uninitialized. + PROTOBUF_ALWAYS_INLINE void* MaybeAllocateStringWithCleanup() { + void* p; + return MaybeAllocateString(p) ? p : nullptr; } PROTOBUF_ALWAYS_INLINE @@ -426,13 +413,6 @@ inline PROTOBUF_ALWAYS_INLINE bool SerialArena::MaybeAllocateString(void*& p) { return false; } -template <> -inline PROTOBUF_ALWAYS_INLINE void* -SerialArena::MaybeAllocateWithCleanup() { - void* p; - return MaybeAllocateString(p) ? p : nullptr; -} - ABSL_ATTRIBUTE_RETURNS_NONNULL inline PROTOBUF_ALWAYS_INLINE void* SerialArena::AllocateFromStringBlock() { void* p;