Allow returning Dictionary after merging

This commit is contained in:
kobewi
2022-09-08 18:14:10 +02:00
parent 9b94c80e9a
commit eb0a624902
4 changed files with 27 additions and 0 deletions

View File

@ -249,6 +249,7 @@ void Dictionary::clear() {
}
void Dictionary::merge(const Dictionary &p_dictionary, bool p_overwrite) {
ERR_FAIL_COND_MSG(_p->read_only, "Dictionary is in read-only state.");
for (const KeyValue<Variant, Variant> &E : p_dictionary._p->variant_map) {
if (p_overwrite || !has(E.key)) {
operator[](E.key) = E.value;
@ -256,6 +257,12 @@ void Dictionary::merge(const Dictionary &p_dictionary, bool p_overwrite) {
}
}
Dictionary Dictionary::merged(const Dictionary &p_dictionary, bool p_overwrite) const {
Dictionary ret = duplicate();
ret.merge(p_dictionary, p_overwrite);
return ret;
}
void Dictionary::_unref() const {
ERR_FAIL_NULL(_p);
if (_p->refcount.unref()) {