diff --git a/include/cppgc/allocation.h b/include/cppgc/allocation.h index 78715fc661..f4f0e72bd5 100644 --- a/include/cppgc/allocation.h +++ b/include/cppgc/allocation.h @@ -43,6 +43,28 @@ class V8_EXPORT MakeGarbageCollectedTraitInternal { std::memory_order_release); } + template + struct SpacePolicy { + static void* Allocate(AllocationHandle& handle, size_t size) { + // Custom space. + static_assert(std::is_base_of::value, + "Custom space must inherit from CustomSpaceBase."); + return MakeGarbageCollectedTraitInternal::Allocate( + handle, size, internal::GCInfoTrait::Index(), + CustomSpace::kSpaceIndex); + } + }; + + template + struct SpacePolicy { + static void* Allocate(AllocationHandle& handle, size_t size) { + // Default space. + return MakeGarbageCollectedTraitInternal::Allocate( + handle, size, internal::GCInfoTrait::Index()); + } + }; + + private: static void* Allocate(cppgc::AllocationHandle& handle, size_t size, GCInfoIndex index); static void* Allocate(cppgc::AllocationHandle& handle, size_t size, @@ -71,27 +93,6 @@ class MakeGarbageCollectedTraitBase internal::api_constants::kLargeObjectSizeThreshold, "GarbageCollectedMixin may not be a large object"); - template - struct SpacePolicy { - static void* Allocate(AllocationHandle& handle, size_t size) { - // Custom space. - static_assert(std::is_base_of::value, - "Custom space must inherit from CustomSpaceBase."); - return internal::MakeGarbageCollectedTraitInternal::Allocate( - handle, size, internal::GCInfoTrait::Index(), - CustomSpace::kSpaceIndex); - } - }; - - template - struct SpacePolicy { - static void* Allocate(AllocationHandle& handle, size_t size) { - // Default space. - return internal::MakeGarbageCollectedTraitInternal::Allocate( - handle, size, internal::GCInfoTrait::Index()); - } - }; - protected: /** * Allocates memory for an object of type T. @@ -101,7 +102,7 @@ class MakeGarbageCollectedTraitBase * \param size The size that should be reserved for the object. * \returns the memory to construct an object of type T on. */ - static void* Allocate(AllocationHandle& handle, size_t size) { + V8_INLINE static void* Allocate(AllocationHandle& handle, size_t size) { return SpacePolicy< typename internal::GCInfoFolding< T, typename T::ParentMostGarbageCollectedType>::ResultType, @@ -114,7 +115,7 @@ class MakeGarbageCollectedTraitBase * * \param payload The base pointer the object is allocated at. */ - static void MarkObjectAsFullyConstructed(const void* payload) { + V8_INLINE static void MarkObjectAsFullyConstructed(const void* payload) { internal::MakeGarbageCollectedTraitInternal::MarkObjectAsFullyConstructed( payload); }