summaryrefslogtreecommitdiff
path: root/core/variant/variant.cpp
diff options
context:
space:
mode:
authorAdam Scott <ascott.ca@gmail.com>2023-01-20 14:36:52 -0500
committerAdam Scott <ascott.ca@gmail.com>2023-01-25 10:46:21 -0500
commit37248d7c87cc4e7350cb29159f5c22a602d489e7 (patch)
treed2b09562656b69b69dfaf4885307a9a6baae8753 /core/variant/variant.cpp
parent9de0c73e4529afe3ea060332a03e17cc0581efd8 (diff)
Add `@GlobalScope` `is_same(a, b)` and `Variant::identity_compare()`
Diffstat (limited to 'core/variant/variant.cpp')
-rw-r--r--core/variant/variant.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp
index ca42738b05..672b030806 100644
--- a/core/variant/variant.cpp
+++ b/core/variant/variant.cpp
@@ -3492,6 +3492,46 @@ bool Variant::hash_compare(const Variant &p_variant, int recursion_count) const
}
}
+bool Variant::identity_compare(const Variant &p_variant) const {
+ if (type != p_variant.type) {
+ return false;
+ }
+
+ switch (type) {
+ case OBJECT: {
+ return _get_obj().obj == p_variant._get_obj().obj;
+ } break;
+
+ case DICTIONARY: {
+ const Dictionary &l = *(reinterpret_cast<const Dictionary *>(_data._mem));
+ const Dictionary &r = *(reinterpret_cast<const Dictionary *>(p_variant._data._mem));
+ return l.id() == r.id();
+ } break;
+
+ case ARRAY: {
+ const Array &l = *(reinterpret_cast<const Array *>(_data._mem));
+ const Array &r = *(reinterpret_cast<const Array *>(p_variant._data._mem));
+ return l.id() == r.id();
+ } break;
+
+ case PACKED_BYTE_ARRAY:
+ case PACKED_INT32_ARRAY:
+ case PACKED_INT64_ARRAY:
+ case PACKED_FLOAT32_ARRAY:
+ case PACKED_FLOAT64_ARRAY:
+ case PACKED_STRING_ARRAY:
+ case PACKED_VECTOR2_ARRAY:
+ case PACKED_VECTOR3_ARRAY:
+ case PACKED_COLOR_ARRAY: {
+ return _data.packed_array == p_variant._data.packed_array;
+ } break;
+
+ default: {
+ return hash_compare(p_variant);
+ }
+ }
+}
+
bool StringLikeVariantComparator::compare(const Variant &p_lhs, const Variant &p_rhs) {
if (p_lhs.hash_compare(p_rhs)) {
return true;