Skip to content

Commit d8eb688

Browse files
Use Dictionary.get_key_list where appropriate
1 parent ef1153b commit d8eb688

13 files changed

+70
-55
lines changed

editor/dependency_editor.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -463,17 +463,18 @@ void DependencyRemoveDialog::_find_localization_remaps_of_removed_files(Vector<R
463463
p_removed.push_back(dep);
464464
}
465465

466-
Array remap_keys = remaps.keys();
467-
for (int j = 0; j < remap_keys.size(); j++) {
468-
PackedStringArray remapped_files = remaps[remap_keys[j]];
466+
List<Variant> remap_keys;
467+
remaps.get_key_list(&remap_keys);
468+
for (const Variant &remap_key : remap_keys) {
469+
PackedStringArray remapped_files = remaps[remap_key];
469470
for (int k = 0; k < remapped_files.size(); k++) {
470471
int splitter_pos = remapped_files[k].rfind_char(':');
471472
String res_path = remapped_files[k].substr(0, splitter_pos);
472473
if (res_path == path) {
473474
String locale_name = remapped_files[k].substr(splitter_pos + 1);
474475

475476
RemovedDependency dep;
476-
dep.file = vformat(TTR("Localization remap for path '%s' and locale '%s'."), remap_keys[j], locale_name);
477+
dep.file = vformat(TTR("Localization remap for path '%s' and locale '%s'."), remap_key, locale_name);
477478
dep.file_type = "";
478479
dep.dependency = path;
479480
dep.dependency_folder = files.value;

editor/editor_command_palette.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,9 @@ void EditorCommandPalette::register_shortcuts_as_command() {
294294

295295
// Load command use history.
296296
Dictionary command_history = EditorSettings::get_singleton()->get_project_metadata("command_palette", "command_history", Dictionary());
297-
Array history_entries = command_history.keys();
298-
for (int i = 0; i < history_entries.size(); i++) {
299-
const String &history_key = history_entries[i];
297+
List<Variant> history_entries;
298+
command_history.get_key_list(&history_entries);
299+
for (const String history_key : history_entries) {
300300
if (commands.has(history_key)) {
301301
commands[history_key].last_used = command_history[history_key];
302302
}

editor/export/editor_export_platform.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,9 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
15681568
}
15691569

15701570
Dictionary int_export = get_internal_export_files(p_preset, p_debug);
1571-
for (const Variant &int_name : int_export.keys()) {
1571+
List<Variant> keys;
1572+
int_export.get_key_list(&keys);
1573+
for (const Variant &int_name : keys) {
15721574
const PackedByteArray &array = int_export[int_name];
15731575
err = save_proxy.save_file(p_udata, int_name, array, idx, total, enc_in_filters, enc_ex_filters, key, seed);
15741576
if (err != OK) {

editor/export/editor_export_preset.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ void EditorExportPreset::update_value_overrides() {
208208

209209
Dictionary plugin_overrides = export_plugins[i]->_get_export_options_overrides(platform);
210210
if (!plugin_overrides.is_empty()) {
211-
Array keys = plugin_overrides.keys();
212-
for (int x = 0; x < keys.size(); x++) {
213-
StringName key = keys[x];
211+
List<Variant> keys;
212+
plugin_overrides.get_key_list(&keys);
213+
for (const StringName key : keys) {
214214
Variant value = plugin_overrides[key];
215215
if (new_value_overrides.has(key) && new_value_overrides[key] != value) {
216216
WARN_PRINT_ED(vformat("Editor export plugin '%s' overrides pre-existing export option override '%s' with new value.", export_plugins[i]->get_name(), key));

editor/import/3d/resource_importer_scene.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -2942,12 +2942,13 @@ static Error convert_path_to_uid(ResourceUID::ID p_source_id, const String &p_ha
29422942
}
29432943

29442944
Error ResourceImporterScene::_check_resource_save_paths(ResourceUID::ID p_source_id, const String &p_hash_suffix, const Dictionary &p_data) {
2945-
Array keys = p_data.keys();
2946-
for (int di = 0; di < keys.size(); di++) {
2947-
Dictionary settings = p_data[keys[di]];
2945+
List<Variant> keys;
2946+
p_data.get_key_list(&keys);
2947+
for (const Variant &key : keys) {
2948+
Dictionary settings = p_data[key];
29482949

29492950
if (bool(settings.get("save_to_file/enabled", false)) && settings.has("save_to_file/path")) {
2950-
String to_hash = keys[di].operator String() + p_hash_suffix;
2951+
String to_hash = key.operator String() + p_hash_suffix;
29512952
Error ret = convert_path_to_uid(p_source_id, to_hash, settings, "save_to_file/path", "save_to_file/fallback_path");
29522953
ERR_FAIL_COND_V_MSG(ret != OK, ret, vformat("Resource save path %s not valid. Ensure parent directory has been created.", settings.has("save_to_file/path")));
29532954
}
@@ -2957,7 +2958,7 @@ Error ResourceImporterScene::_check_resource_save_paths(ResourceUID::ID p_source
29572958
for (int si = 0; si < slice_count; si++) {
29582959
if (bool(settings.get("slice_" + itos(si + 1) + "/save_to_file/enabled", false)) &&
29592960
settings.has("slice_" + itos(si + 1) + "/save_to_file/path")) {
2960-
String to_hash = keys[di].operator String() + p_hash_suffix + itos(si + 1);
2961+
String to_hash = key.operator String() + p_hash_suffix + itos(si + 1);
29612962
Error ret = convert_path_to_uid(p_source_id, to_hash, settings,
29622963
"slice_" + itos(si + 1) + "/save_to_file/path",
29632964
"slice_" + itos(si + 1) + "/save_to_file/fallback_path");

editor/localization_editor.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,10 @@ void LocalizationEditor::_filesystem_files_moved(const String &p_old_file, const
436436
}
437437

438438
// Check for the Array elements of the values.
439-
Array remap_keys = remaps.keys();
440-
for (int i = 0; i < remap_keys.size(); i++) {
441-
PackedStringArray remapped_files = remaps[remap_keys[i]];
439+
List<Variant> remap_keys;
440+
remaps.get_key_list(&remap_keys);
441+
for (const Variant &remap_key : remap_keys) {
442+
PackedStringArray remapped_files = remaps[remap_key];
442443
bool remapped_files_updated = false;
443444

444445
for (int j = 0; j < remapped_files.size(); j++) {
@@ -452,12 +453,12 @@ void LocalizationEditor::_filesystem_files_moved(const String &p_old_file, const
452453
remapped_files.remove_at(j + 1);
453454
remaps_changed = true;
454455
remapped_files_updated = true;
455-
print_verbose(vformat("Changed remap value \"%s\" to \"%s\" of key \"%s\" due to a moved file.", res_path + ":" + locale_name, remapped_files[j], remap_keys[i]));
456+
print_verbose(vformat("Changed remap value \"%s\" to \"%s\" of key \"%s\" due to a moved file.", res_path + ":" + locale_name, remapped_files[j], remap_key));
456457
}
457458
}
458459

459460
if (remapped_files_updated) {
460-
remaps[remap_keys[i]] = remapped_files;
461+
remaps[remap_key] = remapped_files;
461462
}
462463
}
463464

editor/plugins/node_3d_editor_plugin.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -8097,7 +8097,8 @@ void Node3DEditor::_snap_selected_nodes_to_floor() {
80978097
PhysicsDirectSpaceState3D *ss = get_tree()->get_root()->get_world_3d()->get_direct_space_state();
80988098
PhysicsDirectSpaceState3D::RayResult result;
80998099

8100-
Array keys = snap_data.keys();
8100+
List<Variant> keys;
8101+
snap_data.get_key_list(&keys);
81018102

81028103
// The maximum height an object can travel to be snapped
81038104
const float max_snap_height = 500.0;
@@ -8108,8 +8109,8 @@ void Node3DEditor::_snap_selected_nodes_to_floor() {
81088109
if (keys.size()) {
81098110
// For snapping to be performed, there must be solid geometry under at least one of the selected nodes.
81108111
// We need to check this before snapping to register the undo/redo action only if needed.
8111-
for (int i = 0; i < keys.size(); i++) {
8112-
Node *node = Object::cast_to<Node>(keys[i]);
8112+
for (const Variant &key : keys) {
8113+
Node *node = Object::cast_to<Node>(key);
81138114
Node3D *sp = Object::cast_to<Node3D>(node);
81148115
Dictionary d = snap_data[node];
81158116
Vector3 from = d["from"];
@@ -8131,8 +8132,8 @@ void Node3DEditor::_snap_selected_nodes_to_floor() {
81318132
undo_redo->create_action(TTR("Snap Nodes to Floor"));
81328133

81338134
// Perform snapping if at least one node can be snapped
8134-
for (int i = 0; i < keys.size(); i++) {
8135-
Node *node = Object::cast_to<Node>(keys[i]);
8135+
for (const Variant &key : keys) {
8136+
Node *node = Object::cast_to<Node>(key);
81368137
Node3D *sp = Object::cast_to<Node3D>(node);
81378138
Dictionary d = snap_data[node];
81388139
Vector3 from = d["from"];

modules/gltf/editor/editor_import_blend_runner.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ bpy.ops.export_scene.gltf(**opts['gltf_options'])
9292

9393
String dict_to_python(const Dictionary &p_dict) {
9494
String entries;
95-
Array dict_keys = p_dict.keys();
96-
for (int i = 0; i < dict_keys.size(); i++) {
97-
const String key = dict_keys[i];
95+
List<Variant> dict_keys;
96+
p_dict.get_key_list(&dict_keys);
97+
for (const String key : dict_keys) {
9898
String value;
9999
Variant raw_value = p_dict[key];
100100

@@ -125,9 +125,9 @@ String dict_to_python(const Dictionary &p_dict) {
125125

126126
String dict_to_xmlrpc(const Dictionary &p_dict) {
127127
String members;
128-
Array dict_keys = p_dict.keys();
129-
for (int i = 0; i < dict_keys.size(); i++) {
130-
const String key = dict_keys[i];
128+
List<Variant> dict_keys;
129+
p_dict.get_key_list(&dict_keys);
130+
for (const String key : dict_keys) {
131131
String value;
132132
Variant raw_value = p_dict[key];
133133

modules/gltf/gltf_template_convert.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ static Dictionary to_dictionary(const HashMap<K, V> &p_inp) {
8484
template <typename K, typename V>
8585
static void set_from_dictionary(HashMap<K, V> &r_out, const Dictionary &p_inp) {
8686
r_out.clear();
87-
Array keys = p_inp.keys();
88-
for (int i = 0; i < keys.size(); i++) {
89-
r_out[keys[i]] = p_inp[keys[i]];
87+
List<Variant> keys;
88+
p_inp.get_key_list(&keys);
89+
for (const Variant &key : keys) {
90+
r_out[key] = p_inp[key];
9091
}
9192
}
9293
} //namespace GLTFTemplateConvert

modules/gltf/structures/gltf_skin.cpp

+18-11
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ Dictionary GLTFSkin::get_joint_i_to_name() {
145145

146146
void GLTFSkin::set_joint_i_to_name(Dictionary p_joint_i_to_name) {
147147
joint_i_to_name = HashMap<int, StringName>();
148-
Array keys = p_joint_i_to_name.keys();
149-
for (int i = 0; i < keys.size(); i++) {
150-
joint_i_to_name[keys[i]] = p_joint_i_to_name[keys[i]];
148+
List<Variant> keys;
149+
p_joint_i_to_name.get_key_list(&keys);
150+
for (const Variant &key : keys) {
151+
joint_i_to_name[key] = p_joint_i_to_name[key];
151152
}
152153
}
153154

@@ -205,19 +206,25 @@ Error GLTFSkin::from_dictionary(const Dictionary &dict) {
205206
ERR_FAIL_COND_V(!dict.has("joint_i_to_bone_i"), ERR_INVALID_DATA);
206207
Dictionary joint_i_to_bone_i_dict = dict["joint_i_to_bone_i"];
207208
joint_i_to_bone_i.clear();
208-
for (int i = 0; i < joint_i_to_bone_i_dict.keys().size(); ++i) {
209-
int key = joint_i_to_bone_i_dict.keys()[i];
210-
int value = joint_i_to_bone_i_dict[key];
211-
joint_i_to_bone_i[key] = value;
209+
{
210+
List<Variant> keys;
211+
joint_i_to_bone_i_dict.get_key_list(&keys);
212+
for (int key : keys) {
213+
int value = joint_i_to_bone_i_dict[key];
214+
joint_i_to_bone_i[key] = value;
215+
}
212216
}
213217

214218
ERR_FAIL_COND_V(!dict.has("joint_i_to_name"), ERR_INVALID_DATA);
215219
Dictionary joint_i_to_name_dict = dict["joint_i_to_name"];
216220
joint_i_to_name.clear();
217-
for (int i = 0; i < joint_i_to_name_dict.keys().size(); ++i) {
218-
int key = joint_i_to_name_dict.keys()[i];
219-
StringName value = joint_i_to_name_dict[key];
220-
joint_i_to_name[key] = value;
221+
{
222+
List<Variant> keys;
223+
joint_i_to_name_dict.get_key_list(&keys);
224+
for (int key : keys) {
225+
StringName value = joint_i_to_name_dict[key];
226+
joint_i_to_name[key] = value;
227+
}
221228
}
222229
if (dict.has("godot_skin")) {
223230
godot_skin = dict["godot_skin"];

modules/openxr/editor/openxr_select_runtime.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ void OpenXRSelectRuntime::_update_items() {
5454
set_item_metadata(index, "");
5555
index++;
5656

57-
Array keys = runtimes.keys();
58-
for (int i = 0; i < keys.size(); i++) {
59-
String key = keys[i];
57+
List<Variant> keys;
58+
runtimes.get_key_list(&keys);
59+
for (const String key : keys) {
6060
String path = runtimes[key];
6161
String adj_path = path.replace("~", home_folder);
6262

modules/openxr/extensions/openxr_extension_wrapper_extension.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ HashMap<String, bool *> OpenXRExtensionWrapperExtension::get_requested_extension
7979

8080
if (GDVIRTUAL_CALL(_get_requested_extensions, request_extension)) {
8181
HashMap<String, bool *> result;
82-
Array keys = request_extension.keys();
83-
for (int i = 0; i < keys.size(); i++) {
84-
String key = keys.get(i);
82+
List<Variant> keys;
83+
request_extension.get_key_list(&keys);
84+
for (const String key : keys) {
8585
GDExtensionPtr<bool> value = VariantCaster<GDExtensionPtr<bool>>::cast(request_extension.get(key, GDExtensionPtr<bool>(nullptr)));
8686
result.insert(key, value);
8787
}

scene/gui/code_edit.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1247,9 +1247,10 @@ void CodeEdit::add_auto_brace_completion_pair(const String &p_open_key, const St
12471247
void CodeEdit::set_auto_brace_completion_pairs(const Dictionary &p_auto_brace_completion_pairs) {
12481248
auto_brace_completion_pairs.clear();
12491249

1250-
Array keys = p_auto_brace_completion_pairs.keys();
1251-
for (int i = 0; i < keys.size(); i++) {
1252-
add_auto_brace_completion_pair(keys[i], p_auto_brace_completion_pairs[keys[i]]);
1250+
List<Variant> keys;
1251+
p_auto_brace_completion_pairs.get_key_list(&keys);
1252+
for (const Variant &key : keys) {
1253+
add_auto_brace_completion_pair(key, p_auto_brace_completion_pairs[key]);
12531254
}
12541255
}
12551256

0 commit comments

Comments
 (0)