summaryrefslogtreecommitdiff
path: root/core/variant/variant.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-08-02 22:00:53 +0200
committerGitHub <noreply@github.com>2022-08-02 22:00:53 +0200
commit3b39f00761145a44a6c6d45320d6e26b944814a3 (patch)
tree892c712f64d8f4f32765e3359b92cc4729554097 /core/variant/variant.cpp
parentd93c3f03f213c4e6dc9f7d02e34a87d7cd5f9b5c (diff)
parentbb273bc97208db7d8a793956e6caab1e534c997f (diff)
Merge pull request #63834 from lawnjelly/variant_large_bucket_pool
Variant large bucket memory pool - for Projection
Diffstat (limited to 'core/variant/variant.cpp')
-rw-r--r--core/variant/variant.cpp25
1 files changed, 16 insertions, 9 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) {