From 511a4b761c3b5bf565f6e580fc9774a99e72a53e Mon Sep 17 00:00:00 2001 From: George Marques Date: Mon, 27 Jun 2022 12:09:51 -0300 Subject: 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. --- core/variant/variant.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'core/variant/variant.cpp') 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 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: { -- cgit v1.2.3