summaryrefslogtreecommitdiff
path: root/core/variant
diff options
context:
space:
mode:
authorGeorge Marques <george@gmarqu.es>2022-06-27 12:09:51 -0300
committerGeorge Marques <george@gmarqu.es>2022-06-27 12:09:51 -0300
commit511a4b761c3b5bf565f6e580fc9774a99e72a53e (patch)
tree83506363302f698270b87d75edd7e5b9b91a4730 /core/variant
parent307dfa9fe960c93b3f4c2f78d9c046c1ffff6a93 (diff)
GDScript: Fix setter being called in chains for shared types
When a type is shared (i.e. passed by reference) it doesn't need to be called in a setter chain (e.g. `a.b.c = 0`) since it will be updated in place. This commit adds an instruction that jumps when the value is shared so it can be used to skip those cases and avoid redundant calls of setters. It also solves issues when assigning to sub-properties of read-only properties.
Diffstat (limited to 'core/variant')
-rw-r--r--core/variant/variant.cpp19
-rw-r--r--core/variant/variant.h1
2 files changed, 16 insertions, 4 deletions
diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp
index 6007268e21..cc22b9c451 100644
--- a/core/variant/variant.cpp
+++ b/core/variant/variant.cpp
@@ -3327,13 +3327,20 @@ Vector<Variant> varray(const Variant &p_arg1, const Variant &p_arg2, const Varia
void Variant::static_assign(const Variant &p_variant) {
}
-bool Variant::is_shared() const {
- switch (type) {
+bool Variant::is_type_shared(Variant::Type p_type) {
+ switch (p_type) {
case OBJECT:
- return true;
case ARRAY:
- return true;
case DICTIONARY:
+ 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 true;
default: {
}
@@ -3342,6 +3349,10 @@ bool Variant::is_shared() const {
return false;
}
+bool Variant::is_shared() const {
+ return is_type_shared(type);
+}
+
void Variant::_variant_call_error(const String &p_method, Callable::CallError &error) {
switch (error.error) {
case Callable::CallError::CALL_ERROR_INVALID_ARGUMENT: {
diff --git a/core/variant/variant.h b/core/variant/variant.h
index 992d9cad40..cb3a622417 100644
--- a/core/variant/variant.h
+++ b/core/variant/variant.h
@@ -297,6 +297,7 @@ public:
static String get_type_name(Variant::Type p_type);
static bool can_convert(Type p_type_from, Type p_type_to);
static bool can_convert_strict(Type p_type_from, Type p_type_to);
+ static bool is_type_shared(Variant::Type p_type);
bool is_ref_counted() const;
_FORCE_INLINE_ bool is_num() const {