diff options
Diffstat (limited to 'src/google/protobuf/arena.h')
-rw-r--r-- | src/google/protobuf/arena.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index 879fd0d3..05e05ebc 100644 --- a/src/google/protobuf/arena.h +++ b/src/google/protobuf/arena.h @@ -322,6 +322,17 @@ class LIBPROTOBUF_EXPORT Arena { arg); } } +#if LANG_CXX11 + template <typename T, typename Arg> GOOGLE_ATTRIBUTE_ALWAYS_INLINE + static T* Create(::google::protobuf::Arena* arena, Arg&& arg) { + if (arena == NULL) { + return new T(std::move(arg)); + } else { + return arena->CreateInternal<T>(google::protobuf::internal::has_trivial_destructor<T>::value, + std::move(arg)); + } + } +#endif // Version of the above with two constructor arguments for the created object. template <typename T, typename Arg1, typename Arg2> GOOGLE_ATTRIBUTE_ALWAYS_INLINE @@ -662,6 +673,18 @@ class LIBPROTOBUF_EXPORT Arena { return t; } +#if LANG_CXX11 + template <typename T, typename Arg> GOOGLE_ATTRIBUTE_ALWAYS_INLINE + T* CreateInternal(bool skip_explicit_ownership, Arg&& arg) { + T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) T( + std::move(arg)); + if (!skip_explicit_ownership) { + AddListNode(t, &internal::arena_destruct_object<T>); + } + return t; + } +#endif + template <typename T, typename Arg1, typename Arg2> GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* CreateInternal( bool skip_explicit_ownership, const Arg1& arg1, const Arg2& arg2) { |