summaryrefslogtreecommitdiffstats
path: root/core/extension
diff options
context:
space:
mode:
authorA Thousand Ships <96648715+AThousandShips@users.noreply.github.com>2023-12-24 13:44:21 +0100
committerA Thousand Ships <96648715+AThousandShips@users.noreply.github.com>2024-04-10 14:49:34 +0200
commit64146cb7f35b57b0974b82845674d58f9f3480b6 (patch)
treebbfae7eca9992c0dcdf2ee237dd56f9d742d6c77 /core/extension
parent1f0f81049fc470fe10ddb64086c94b9c595ec81f (diff)
downloadredot-engine-64146cb7f35b57b0974b82845674d58f9f3480b6.tar.gz
[Core] Add iteration support to `Array`
Diffstat (limited to 'core/extension')
-rw-r--r--core/extension/extension_api_dump.cpp24
1 files changed, 10 insertions, 14 deletions
diff --git a/core/extension/extension_api_dump.cpp b/core/extension/extension_api_dump.cpp
index 543dabfb16..69be2d2a8f 100644
--- a/core/extension/extension_api_dump.cpp
+++ b/core/extension/extension_api_dump.cpp
@@ -1313,9 +1313,7 @@ static bool compare_value(const String &p_path, const String &p_field, const Var
} else if (p_old_value.get_type() == Variant::DICTIONARY && p_new_value.get_type() == Variant::DICTIONARY) {
Dictionary old_dict = p_old_value;
Dictionary new_dict = p_new_value;
- Array old_keys = old_dict.keys();
- for (int i = 0; i < old_keys.size(); i++) {
- Variant key = old_keys[i];
+ for (const Variant &key : old_dict.keys()) {
if (!new_dict.has(key)) {
failed = true;
print_error(vformat("Validate extension JSON: Error: Field '%s': %s was removed.", p_path, key));
@@ -1328,9 +1326,7 @@ static bool compare_value(const String &p_path, const String &p_field, const Var
failed = true;
}
}
- Array new_keys = old_dict.keys();
- for (int i = 0; i < new_keys.size(); i++) {
- Variant key = new_keys[i];
+ for (const Variant &key : old_dict.keys()) {
if (!old_dict.has(key)) {
failed = true;
print_error(vformat("Validate extension JSON: Error: Field '%s': %s was added with value %s.", p_path, key, new_dict[key]));
@@ -1356,8 +1352,8 @@ static bool compare_dict_array(const Dictionary &p_old_api, const Dictionary &p_
Array new_api = p_new_api[p_base_array];
HashMap<String, Dictionary> new_api_assoc;
- for (int i = 0; i < new_api.size(); i++) {
- Dictionary elem = new_api[i];
+ for (const Variant &var : new_api) {
+ Dictionary elem = var;
ERR_FAIL_COND_V_MSG(!elem.has(p_name_field), false, vformat("Validate extension JSON: Element of base_array '%s' is missing field '%s'. This is a bug.", base_array, p_name_field));
String name = elem[p_name_field];
if (p_compare_operators && elem.has("right_type")) {
@@ -1367,8 +1363,8 @@ static bool compare_dict_array(const Dictionary &p_old_api, const Dictionary &p_
}
Array old_api = p_old_api[p_base_array];
- for (int i = 0; i < old_api.size(); i++) {
- Dictionary old_elem = old_api[i];
+ for (const Variant &var : old_api) {
+ Dictionary old_elem = var;
if (!old_elem.has(p_name_field)) {
failed = true;
print_error(vformat("Validate extension JSON: JSON file: element of base array '%s' is missing the field: '%s'.", base_array, p_name_field));
@@ -1508,16 +1504,16 @@ static bool compare_sub_dict_array(HashSet<String> &r_removed_classes_registered
Array new_api = p_new_api[p_outer];
HashMap<String, Dictionary> new_api_assoc;
- for (int i = 0; i < new_api.size(); i++) {
- Dictionary elem = new_api[i];
+ for (const Variant &var : new_api) {
+ Dictionary elem = var;
ERR_FAIL_COND_V_MSG(!elem.has(p_outer_name), false, vformat("Validate extension JSON: Element of base_array '%s' is missing field '%s'. This is a bug.", p_outer, p_outer_name));
new_api_assoc.insert(elem[p_outer_name], elem);
}
Array old_api = p_old_api[p_outer];
- for (int i = 0; i < old_api.size(); i++) {
- Dictionary old_elem = old_api[i];
+ for (const Variant &var : old_api) {
+ Dictionary old_elem = var;
if (!old_elem.has(p_outer_name)) {
failed = true;
print_error(vformat("Validate extension JSON: JSON file: element of base array '%s' is missing the field: '%s'.", p_outer, p_outer_name));