Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't set Variant::Type in destructor #100795

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 49 additions & 47 deletions core/variant/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,53 +275,53 @@ class Variant {

void _clear_internal();

_FORCE_INLINE_ void clear() {
static const bool needs_deinit[Variant::VARIANT_MAX] = {
false, //NIL,
false, //BOOL,
false, //INT,
false, //FLOAT,
true, //STRING,
false, //VECTOR2,
false, //VECTOR2I,
false, //RECT2,
false, //RECT2I,
false, //VECTOR3,
false, //VECTOR3I,
true, //TRANSFORM2D,
false, //VECTOR4,
false, //VECTOR4I,
false, //PLANE,
false, //QUATERNION,
true, //AABB,
true, //BASIS,
true, //TRANSFORM,
true, //PROJECTION,

// misc types
false, //COLOR,
true, //STRING_NAME,
true, //NODE_PATH,
false, //RID,
true, //OBJECT,
true, //CALLABLE,
true, //SIGNAL,
true, //DICTIONARY,
true, //ARRAY,

// typed arrays
true, //PACKED_BYTE_ARRAY,
true, //PACKED_INT32_ARRAY,
true, //PACKED_INT64_ARRAY,
true, //PACKED_FLOAT32_ARRAY,
true, //PACKED_FLOAT64_ARRAY,
true, //PACKED_STRING_ARRAY,
true, //PACKED_VECTOR2_ARRAY,
true, //PACKED_VECTOR3_ARRAY,
true, //PACKED_COLOR_ARRAY,
true, //PACKED_VECTOR4_ARRAY,
};
static constexpr bool needs_deinit[Variant::VARIANT_MAX] = {
false, //NIL,
false, //BOOL,
false, //INT,
false, //FLOAT,
true, //STRING,
false, //VECTOR2,
false, //VECTOR2I,
false, //RECT2,
false, //RECT2I,
false, //VECTOR3,
false, //VECTOR3I,
true, //TRANSFORM2D,
false, //VECTOR4,
false, //VECTOR4I,
false, //PLANE,
false, //QUATERNION,
true, //AABB,
true, //BASIS,
true, //TRANSFORM,
true, //PROJECTION,

// misc types
false, //COLOR,
true, //STRING_NAME,
true, //NODE_PATH,
false, //RID,
true, //OBJECT,
true, //CALLABLE,
true, //SIGNAL,
true, //DICTIONARY,
true, //ARRAY,

// typed arrays
true, //PACKED_BYTE_ARRAY,
true, //PACKED_INT32_ARRAY,
true, //PACKED_INT64_ARRAY,
true, //PACKED_FLOAT32_ARRAY,
true, //PACKED_FLOAT64_ARRAY,
true, //PACKED_STRING_ARRAY,
true, //PACKED_VECTOR2_ARRAY,
true, //PACKED_VECTOR3_ARRAY,
true, //PACKED_COLOR_ARRAY,
true, //PACKED_VECTOR4_ARRAY,
};

_FORCE_INLINE_ void clear() {
if (unlikely(needs_deinit[type])) { // Make it fast for types that don't need deinit.
_clear_internal();
}
Expand Down Expand Up @@ -832,7 +832,9 @@ class Variant {
}
_FORCE_INLINE_ Variant() {}
_FORCE_INLINE_ ~Variant() {
clear();
if (unlikely(needs_deinit[type])) { // Make it fast for types that don't need deinit.
_clear_internal();
}
}
};

Expand Down