From d64a2d9941c36a7bc2a7959ea10ab8363192ac14 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Wed, 29 Jun 2016 15:23:27 -0700 Subject: Integrated internal changes from Google This includes all internal changes from around May 20 to now. --- src/google/protobuf/repeated_field.h | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'src/google/protobuf/repeated_field.h') diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index 1961bc48..38358dbb 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -564,12 +564,16 @@ class GenericTypeHandler { return ::google::protobuf::Arena::CreateMaybeMessage( arena, static_cast(0)); } - // We force NewFromPrototype() and Delete() to be non-inline to reduce code - // size: else, several other methods get inlined copies of message types' - // constructors and destructors. + // We force NewFromPrototype() to be non-inline to reduce code size: + // else, several other methods get inlined copies of message types' + // constructors. GOOGLE_ATTRIBUTE_NOINLINE static GenericType* NewFromPrototype( const GenericType* prototype, ::google::protobuf::Arena* arena = NULL); - GOOGLE_ATTRIBUTE_NOINLINE static void Delete(GenericType* value, Arena* arena); + static inline void Delete(GenericType* value, Arena* arena) { + if (arena == NULL) { + delete value; + } + } static inline ::google::protobuf::Arena* GetArena(GenericType* value) { return ::google::protobuf::Arena::GetArena(value); } @@ -594,12 +598,6 @@ GenericType* GenericTypeHandler::NewFromPrototype( return New(arena); } template -void GenericTypeHandler::Delete(GenericType* value, Arena* arena) { - if (arena == NULL) { - delete value; - } -} -template void GenericTypeHandler::Merge(const GenericType& from, GenericType* to) { to->MergeFrom(from); @@ -1359,13 +1357,13 @@ inline RepeatedPtrFieldBase::RepeatedPtrFieldBase(::google::protobuf::Arena* are template void RepeatedPtrFieldBase::Destroy() { - if (rep_ != NULL) { - for (int i = 0; i < rep_->allocated_size; i++) { - TypeHandler::Delete(cast(rep_->elements[i]), arena_); - } - if (arena_ == NULL) { - delete [] reinterpret_cast(rep_); + if (rep_ != NULL && arena_ == NULL) { + int n = rep_->allocated_size; + void* const* elements = rep_->elements; + for (int i = 0; i < n; i++) { + TypeHandler::Delete(cast(elements[i]), NULL); } + delete[] reinterpret_cast(rep_); } rep_ = NULL; } -- cgit v1.2.3