diff options
Diffstat (limited to 'core/variant')
-rw-r--r-- | core/variant/array.cpp | 10 | ||||
-rw-r--r-- | core/variant/array.h | 2 | ||||
-rw-r--r-- | core/variant/dictionary.cpp | 10 | ||||
-rw-r--r-- | core/variant/dictionary.h | 2 | ||||
-rw-r--r-- | core/variant/variant_call.cpp | 4 |
5 files changed, 9 insertions, 19 deletions
diff --git a/core/variant/array.cpp b/core/variant/array.cpp index f8af78f3c1..94d1596514 100644 --- a/core/variant/array.cpp +++ b/core/variant/array.cpp @@ -775,15 +775,9 @@ Variant Array::get_typed_script() const { return _p->typed.script; } -void Array::set_read_only(bool p_enable) { - if (p_enable == bool(_p->read_only != nullptr)) { - return; - } - if (p_enable) { +void Array::make_read_only() { + if (_p->read_only == nullptr) { _p->read_only = memnew(Variant); - } else { - memdelete(_p->read_only); - _p->read_only = nullptr; } } diff --git a/core/variant/array.h b/core/variant/array.h index 3728c22fe0..d9ca3278fb 100644 --- a/core/variant/array.h +++ b/core/variant/array.h @@ -127,7 +127,7 @@ public: StringName get_typed_class_name() const; Variant get_typed_script() const; - void set_read_only(bool p_enable); + void make_read_only(); bool is_read_only() const; Array(const Array &p_base, uint32_t p_type, const StringName &p_class_name, const Variant &p_script); diff --git a/core/variant/dictionary.cpp b/core/variant/dictionary.cpp index f87064a0d1..0429508cc5 100644 --- a/core/variant/dictionary.cpp +++ b/core/variant/dictionary.cpp @@ -333,15 +333,9 @@ Dictionary Dictionary::duplicate(bool p_deep) const { return recursive_duplicate(p_deep, 0); } -void Dictionary::set_read_only(bool p_enable) { - if (p_enable == bool(_p->read_only != nullptr)) { - return; - } - if (p_enable) { +void Dictionary::make_read_only() { + if (_p->read_only == nullptr) { _p->read_only = memnew(Variant); - } else { - memdelete(_p->read_only); - _p->read_only = nullptr; } } bool Dictionary::is_read_only() const { diff --git a/core/variant/dictionary.h b/core/variant/dictionary.h index e6d8ebe25b..8935d35ed9 100644 --- a/core/variant/dictionary.h +++ b/core/variant/dictionary.h @@ -86,7 +86,7 @@ public: Dictionary duplicate(bool p_deep = false) const; Dictionary recursive_duplicate(bool p_deep, int recursion_count) const; - void set_read_only(bool p_enable); + void make_read_only(); bool is_read_only() const; const void *id() const; diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 9e8c6fccb3..07e1442faf 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -2179,6 +2179,8 @@ static void _register_variant_builtin_methods() { bind_method(Dictionary, values, sarray(), varray()); bind_method(Dictionary, duplicate, sarray("deep"), varray(false)); bind_method(Dictionary, get, sarray("key", "default"), varray(Variant())); + bind_method(Dictionary, make_read_only, sarray(), varray()); + bind_method(Dictionary, is_read_only, sarray(), varray()); /* Array */ @@ -2226,7 +2228,7 @@ static void _register_variant_builtin_methods() { bind_method(Array, get_typed_builtin, sarray(), varray()); bind_method(Array, get_typed_class_name, sarray(), varray()); bind_method(Array, get_typed_script, sarray(), varray()); - bind_method(Array, set_read_only, sarray("enable"), varray()); + bind_method(Array, make_read_only, sarray(), varray()); bind_method(Array, is_read_only, sarray(), varray()); /* Byte Array */ |