diff options
Diffstat (limited to 'src/google/protobuf/arena.h')
-rw-r--r-- | src/google/protobuf/arena.h | 97 |
1 files changed, 48 insertions, 49 deletions
diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index 16e0d50e..b3d66d91 100644 --- a/src/google/protobuf/arena.h +++ b/src/google/protobuf/arena.h @@ -56,6 +56,7 @@ using type_info = ::type_info; #include <google/protobuf/stubs/mutex.h> #include <google/protobuf/stubs/type_traits.h> + namespace google { namespace protobuf { @@ -76,7 +77,7 @@ template<typename T> void arena_destruct_object(void* object) { template<typename T> void arena_delete_object(void* object) { delete reinterpret_cast<T*>(object); } -inline void arena_free(void* object, size_t size) { +inline void arena_free(void* object, size_t /* size */) { free(object); } @@ -210,7 +211,12 @@ struct ArenaOptions { // // This protocol is implemented by all arena-enabled proto2 message classes as // well as RepeatedPtrField. + +#if __cplusplus >= 201103L +class Arena final { +#else class LIBPROTOBUF_EXPORT Arena { +#endif public: // Arena constructor taking custom options. See ArenaOptions below for // descriptions of the options available. @@ -446,6 +452,10 @@ class LIBPROTOBUF_EXPORT Arena { // As above, but does not include any free space in underlying blocks. GOOGLE_ATTRIBUTE_NOINLINE uint64 SpaceUsed() const; + // Combines SpaceAllocated and SpaceUsed. Returns a pair of + // <space_allocated, space_used>. + GOOGLE_ATTRIBUTE_NOINLINE pair<uint64, uint64> SpaceAllocatedAndUsed() const; + // Frees all storage allocated by this arena after calling destructors // registered with OwnDestructor() and freeing objects registered with Own(). // Any objects allocated on this arena are unusable after this call. It also @@ -490,27 +500,28 @@ class LIBPROTOBUF_EXPORT Arena { return GetArenaInternal(value, static_cast<T*>(0)); } - // Helper typetrait that indicates support for arenas in a type T at compile - // time. This is public only to allow construction of higher-level templated - // utilities. is_arena_constructable<T>::value is an instance of - // google::protobuf::internal::true_type if the message type T has arena support enabled, and - // google::protobuf::internal::false_type otherwise. - // - // This is inside Arena because only Arena has the friend relationships - // necessary to see the underlying generated code traits. - template<typename T> - struct is_arena_constructable { + private: + struct InternalIsArenaConstructableHelper { template<typename U> static char ArenaConstructable( const typename U::InternalArenaConstructable_*); template<typename U> static double ArenaConstructable(...); + }; - // This will resolve to either google::protobuf::internal::true_type or google::protobuf::internal::false_type. - typedef google::protobuf::internal::integral_constant<bool, - sizeof(ArenaConstructable<const T>(static_cast<const T*>(0))) == - sizeof(char)> type; - static const type value; + public: + // Helper typetrait that indicates support for arenas in a type T at compile + // time. This is public only to allow construction of higher-level templated + // utilities. is_arena_constructable<T>::value is true if the message type T + // has arena support enabled, and false otherwise. + // + // This is inside Arena because only Arena has the friend relationships + // necessary to see the underlying generated code traits. + template <typename T> + struct is_arena_constructable + : public google::protobuf::internal::integral_constant< + bool, sizeof(InternalIsArenaConstructableHelper::ArenaConstructable< + const T>(static_cast<const T*>(0))) == sizeof(char)> { }; private: @@ -572,34 +583,30 @@ class LIBPROTOBUF_EXPORT Arena { return google::protobuf::internal::has_trivial_destructor<T>::value; } - // Helper typetrait that indicates whether the desctructor of type T should be - // called when arena is destroyed at compile time. This is only to allow - // construction of higher-level templated utilities. - // is_destructor_skippable<T>::value is an instance of google::protobuf::internal::true_type if the - // destructor of the message type T should not be called when arena is - // destroyed or google::protobuf::internal::has_trivial_destructor<T>::value == true, and - // google::protobuf::internal::false_type otherwise. - // - // This is inside Arena because only Arena has the friend relationships - // necessary to see the underlying generated code traits. - template<typename T> - struct is_destructor_skippable { + private: + struct InternalIsDestructorSkippableHelper { template<typename U> static char DestructorSkippable( const typename U::DestructorSkippable_*); template<typename U> static double DestructorSkippable(...); - - // The raw_skippable_value const bool variable is separated from the typedef - // line below as a work-around of an NVCC 7.0 (and earlier) compiler bug. - static const bool raw_skippable_value = - sizeof(DestructorSkippable<const T>(static_cast<const T*>(0))) == - sizeof(char) || google::protobuf::internal::has_trivial_destructor<T>::value == true; - // This will resolve to either google::protobuf::internal::true_type or google::protobuf::internal::false_type. - typedef google::protobuf::internal::integral_constant<bool, raw_skippable_value> type; - static const type value; }; + public: + // Helper typetrait that indicates whether the desctructor of type T should be + // called when arena is destroyed at compile time. This is only to allow + // construction of higher-level templated utilities. + // is_destructor_skippable<T>::value is true if the destructor of the message + // type T should not be called when arena is destroyed or false otherwise. + // This is inside Arena because only Arena has the friend relationships + // necessary to see the underlying generated code traits. + template<typename T> + struct is_destructor_skippable + : public google::protobuf::internal::integral_constant< + bool, + sizeof(InternalIsDestructorSkippableHelper::DestructorSkippable< + const T>(static_cast<const T*>(0))) == sizeof(char) || + google::protobuf::internal::has_trivial_destructor<T>::value> {}; // CreateMessage<T> requires that T supports arenas, but this private method // works whether or not T supports arenas. These are not exposed to user code @@ -780,8 +787,10 @@ class LIBPROTOBUF_EXPORT Arena { // which needs to declare google::protobuf::Map as friend of generated message. template <typename T> static void CreateInArenaStorage(T* ptr, Arena* arena) { - CreateInArenaStorageInternal(ptr, arena, is_arena_constructable<T>::value); - RegisterDestructorInternal(ptr, arena, is_destructor_skippable<T>::value); + CreateInArenaStorageInternal(ptr, arena, + typename is_arena_constructable<T>::type()); + RegisterDestructorInternal(ptr, arena, + typename is_destructor_skippable<T>::type()); } template <typename T> @@ -910,16 +919,6 @@ class LIBPROTOBUF_EXPORT Arena { // Defined above for supporting environments without RTTI. #undef RTTI_TYPE_ID -template<typename T> -const typename Arena::is_arena_constructable<T>::type - Arena::is_arena_constructable<T>::value = - typename Arena::is_arena_constructable<T>::type(); - -template<typename T> -const typename Arena::is_destructor_skippable<T>::type - Arena::is_destructor_skippable<T>::value = - typename Arena::is_destructor_skippable<T>::type(); - } // namespace protobuf } // namespace google |