diff options
author | Adam Cozzette <acozzette@google.com> | 2016-06-29 15:23:27 -0700 |
---|---|---|
committer | Adam Cozzette <acozzette@google.com> | 2016-06-29 15:38:03 -0700 |
commit | d64a2d9941c36a7bc2a7959ea10ab8363192ac14 (patch) | |
tree | 52330d146ad63d3d70f3baade00d5d1fea8f5e0c /src/google/protobuf/repeated_field.h | |
parent | c18aa7795a2e02ef700ff8b039d94ecdcc33432f (diff) |
Integrated internal changes from Google
This includes all internal changes from around May 20 to now.
Diffstat (limited to 'src/google/protobuf/repeated_field.h')
-rw-r--r-- | src/google/protobuf/repeated_field.h | 30 |
1 files changed, 14 insertions, 16 deletions
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<Type>( arena, static_cast<GenericType*>(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<Type>(value); } @@ -594,12 +598,6 @@ GenericType* GenericTypeHandler<GenericType>::NewFromPrototype( return New(arena); } template <typename GenericType> -void GenericTypeHandler<GenericType>::Delete(GenericType* value, Arena* arena) { - if (arena == NULL) { - delete value; - } -} -template <typename GenericType> void GenericTypeHandler<GenericType>::Merge(const GenericType& from, GenericType* to) { to->MergeFrom(from); @@ -1359,13 +1357,13 @@ inline RepeatedPtrFieldBase::RepeatedPtrFieldBase(::google::protobuf::Arena* are template <typename TypeHandler> void RepeatedPtrFieldBase::Destroy() { - if (rep_ != NULL) { - for (int i = 0; i < rep_->allocated_size; i++) { - TypeHandler::Delete(cast<TypeHandler>(rep_->elements[i]), arena_); - } - if (arena_ == NULL) { - delete [] reinterpret_cast<char*>(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<TypeHandler>(elements[i]), NULL); } + delete[] reinterpret_cast<char*>(rep_); } rep_ = NULL; } |