diff options
author | lawnjelly <lawnjelly@gmail.com> | 2022-08-02 16:27:57 +0100 |
---|---|---|
committer | lawnjelly <lawnjelly@gmail.com> | 2022-08-02 16:27:57 +0100 |
commit | bb273bc97208db7d8a793956e6caab1e534c997f (patch) | |
tree | f3ffcbfa40e1e82c7cb0ece6c9ac7595f529ec7e | |
parent | 0f9e84feab42473b19699372961a81ad2f801c63 (diff) |
Variant large bucket memory pool - for Projection
Add a larger bucket size pool for the new Projection Matrix.
-rw-r--r-- | core/variant/variant.cpp | 25 | ||||
-rw-r--r-- | core/variant/variant.h | 10 | ||||
-rw-r--r-- | core/variant/variant_internal.h | 7 |
3 files changed, 28 insertions, 14 deletions
diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index 504eaa4de6..a5bc6c229d 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -40,6 +40,7 @@ #include "core/variant/variant_parser.h" PagedAllocator<Variant::Pools::BucketSmall, true> Variant::Pools::_bucket_small; +PagedAllocator<Variant::Pools::BucketMedium, true> Variant::Pools::_bucket_medium; PagedAllocator<Variant::Pools::BucketLarge, true> Variant::Pools::_bucket_large; String Variant::get_type_name(Variant::Type p_type) { @@ -1191,15 +1192,16 @@ void Variant::reference(const Variant &p_variant) { memnew_placement(_data._mem, Quaternion(*reinterpret_cast<const Quaternion *>(p_variant._data._mem))); } break; case BASIS: { - _data._basis = (Basis *)Pools::_bucket_large.alloc(); + _data._basis = (Basis *)Pools::_bucket_medium.alloc(); memnew_placement(_data._basis, Basis(*p_variant._data._basis)); } break; case TRANSFORM3D: { - _data._transform3d = (Transform3D *)Pools::_bucket_large.alloc(); + _data._transform3d = (Transform3D *)Pools::_bucket_medium.alloc(); memnew_placement(_data._transform3d, Transform3D(*p_variant._data._transform3d)); } break; case PROJECTION: { - _data._projection = memnew(Projection(*p_variant._data._projection)); + _data._projection = (Projection *)Pools::_bucket_large.alloc(); + memnew_placement(_data._projection, Projection(*p_variant._data._projection)); } break; // misc types @@ -1401,19 +1403,23 @@ void Variant::_clear_internal() { case BASIS: { if (_data._basis) { _data._basis->~Basis(); - Pools::_bucket_large.free((Pools::BucketLarge *)_data._basis); + Pools::_bucket_medium.free((Pools::BucketMedium *)_data._basis); _data._basis = nullptr; } } break; case TRANSFORM3D: { if (_data._transform3d) { _data._transform3d->~Transform3D(); - Pools::_bucket_large.free((Pools::BucketLarge *)_data._transform3d); + Pools::_bucket_medium.free((Pools::BucketMedium *)_data._transform3d); _data._transform3d = nullptr; } } break; case PROJECTION: { - memdelete(_data._projection); + if (_data._projection) { + _data._projection->~Projection(); + Pools::_bucket_large.free((Pools::BucketLarge *)_data._projection); + _data._projection = nullptr; + } } break; // misc types case STRING_NAME: { @@ -2635,7 +2641,7 @@ Variant::Variant(const ::AABB &p_aabb) { Variant::Variant(const Basis &p_matrix) { type = BASIS; - _data._basis = (Basis *)Pools::_bucket_large.alloc(); + _data._basis = (Basis *)Pools::_bucket_medium.alloc(); memnew_placement(_data._basis, Basis(p_matrix)); } @@ -2646,13 +2652,14 @@ Variant::Variant(const Quaternion &p_quaternion) { Variant::Variant(const Transform3D &p_transform) { type = TRANSFORM3D; - _data._transform3d = (Transform3D *)Pools::_bucket_large.alloc(); + _data._transform3d = (Transform3D *)Pools::_bucket_medium.alloc(); memnew_placement(_data._transform3d, Transform3D(p_transform)); } Variant::Variant(const Projection &pp_projection) { type = PROJECTION; - _data._projection = memnew(Projection(pp_projection)); + _data._projection = (Projection *)Pools::_bucket_large.alloc(); + memnew_placement(_data._projection, Projection(pp_projection)); } Variant::Variant(const Transform2D &p_transform) { diff --git a/core/variant/variant.h b/core/variant/variant.h index ea75dce4ce..212f94a9a8 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -142,14 +142,20 @@ private: Transform2D _transform2d; ::AABB _aabb; }; + union BucketMedium { + BucketMedium() {} + ~BucketMedium() {} + Basis _basis; + Transform3D _transform3d; + }; union BucketLarge { BucketLarge() {} ~BucketLarge() {} - Basis _basis; - Transform3D _transform3d; + Projection _projection; }; static PagedAllocator<BucketSmall, true> _bucket_small; + static PagedAllocator<BucketMedium, true> _bucket_medium; static PagedAllocator<BucketLarge, true> _bucket_large; }; diff --git a/core/variant/variant_internal.h b/core/variant/variant_internal.h index 51ca4971db..874a183d29 100644 --- a/core/variant/variant_internal.h +++ b/core/variant/variant_internal.h @@ -227,17 +227,18 @@ public: v->type = Variant::AABB; } _FORCE_INLINE_ static void init_basis(Variant *v) { - v->_data._basis = (Basis *)Variant::Pools::_bucket_large.alloc(); + v->_data._basis = (Basis *)Variant::Pools::_bucket_medium.alloc(); memnew_placement(v->_data._basis, Basis); v->type = Variant::BASIS; } _FORCE_INLINE_ static void init_transform(Variant *v) { - v->_data._transform3d = (Transform3D *)Variant::Pools::_bucket_large.alloc(); + v->_data._transform3d = (Transform3D *)Variant::Pools::_bucket_medium.alloc(); memnew_placement(v->_data._transform3d, Transform3D); v->type = Variant::TRANSFORM3D; } _FORCE_INLINE_ static void init_projection(Variant *v) { - v->_data._projection = memnew(Projection); + v->_data._projection = (Projection *)Variant::Pools::_bucket_large.alloc(); + memnew_placement(v->_data._projection, Projection); v->type = Variant::PROJECTION; } _FORCE_INLINE_ static void init_string_name(Variant *v) { |