Skip to content

Commit

Permalink
Use Dictionary.get_key_list where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
AThousandShips committed Oct 22, 2024
1 parent b3bcb2d commit 9ab9954
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 44 deletions.
9 changes: 5 additions & 4 deletions editor/dependency_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,17 +467,18 @@ void DependencyRemoveDialog::_find_localization_remaps_of_removed_files(Vector<R
p_removed.push_back(dep);
}

Array remap_keys = remaps.keys();
for (int j = 0; j < remap_keys.size(); j++) {
PackedStringArray remapped_files = remaps[remap_keys[j]];
List<Variant> remap_keys;
remaps.get_key_list(&remap_keys);
for (const Variant &remap_key : remap_keys) {
PackedStringArray remapped_files = remaps[remap_key];
for (int k = 0; k < remapped_files.size(); k++) {
int splitter_pos = remapped_files[k].rfind(":");
String res_path = remapped_files[k].substr(0, splitter_pos);
if (res_path == path) {
String locale_name = remapped_files[k].substr(splitter_pos + 1);

RemovedDependency dep;
dep.file = vformat(TTR("Localization remap for path '%s' and locale '%s'."), remap_keys[j], locale_name);
dep.file = vformat(TTR("Localization remap for path '%s' and locale '%s'."), remap_key, locale_name);
dep.file_type = "";
dep.dependency = path;
dep.dependency_folder = files.value;
Expand Down
6 changes: 3 additions & 3 deletions editor/editor_command_palette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ void EditorCommandPalette::register_shortcuts_as_command() {

// Load command use history.
Dictionary command_history = EditorSettings::get_singleton()->get_project_metadata("command_palette", "command_history", Dictionary());
Array history_entries = command_history.keys();
for (int i = 0; i < history_entries.size(); i++) {
const String &history_key = history_entries[i];
List<Variant> history_entries;
command_history.get_key_list(&history_entries);
for (const String history_key : history_entries) {
if (commands.has(history_key)) {
commands[history_key].last_used = command_history[history_key];
}
Expand Down
6 changes: 3 additions & 3 deletions editor/export/editor_export_preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ void EditorExportPreset::update_value_overrides() {

Dictionary plugin_overrides = export_plugins[i]->_get_export_options_overrides(platform);
if (!plugin_overrides.is_empty()) {
Array keys = plugin_overrides.keys();
for (int x = 0; x < keys.size(); x++) {
StringName key = keys[x];
List<Variant> keys;
plugin_overrides.get_key_list(&keys);
for (const StringName key : keys) {
Variant value = plugin_overrides[key];
if (new_value_overrides.has(key) && new_value_overrides[key] != value) {
WARN_PRINT_ED(vformat("Editor export plugin '%s' overrides pre-existing export option override '%s' with new value.", export_plugins[i]->get_name(), key));
Expand Down
7 changes: 4 additions & 3 deletions editor/import/3d/resource_importer_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2869,9 +2869,10 @@ Node *ResourceImporterScene::pre_import(const String &p_source_file, const HashM
}

Error ResourceImporterScene::_check_resource_save_paths(const Dictionary &p_data) {
Array keys = p_data.keys();
for (int i = 0; i < keys.size(); i++) {
const Dictionary &settings = p_data[keys[i]];
List<Variant> keys;
p_data.get_key_list(&keys);
for (const Variant &key : keys) {
const Dictionary &settings = p_data[key];

if (bool(settings.get("save_to_file/enabled", false)) && settings.has("save_to_file/path")) {
const String &save_path = settings["save_to_file/path"];
Expand Down
11 changes: 6 additions & 5 deletions editor/localization_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,10 @@ void LocalizationEditor::_filesystem_files_moved(const String &p_old_file, const
}

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

for (int j = 0; j < remapped_files.size(); j++) {
Expand All @@ -451,12 +452,12 @@ void LocalizationEditor::_filesystem_files_moved(const String &p_old_file, const
remapped_files.remove_at(j + 1);
remaps_changed = true;
remapped_files_updated = true;
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]));
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));
}
}

if (remapped_files_updated) {
remaps[remap_keys[i]] = remapped_files;
remaps[remap_key] = remapped_files;
}
}

Expand Down
11 changes: 6 additions & 5 deletions editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7869,7 +7869,8 @@ void Node3DEditor::_snap_selected_nodes_to_floor() {
PhysicsDirectSpaceState3D *ss = get_tree()->get_root()->get_world_3d()->get_direct_space_state();
PhysicsDirectSpaceState3D::RayResult result;

Array keys = snap_data.keys();
List<Variant> keys;
snap_data.get_key_list(&keys);

// The maximum height an object can travel to be snapped
const float max_snap_height = 500.0;
Expand All @@ -7880,8 +7881,8 @@ void Node3DEditor::_snap_selected_nodes_to_floor() {
if (keys.size()) {
// For snapping to be performed, there must be solid geometry under at least one of the selected nodes.
// We need to check this before snapping to register the undo/redo action only if needed.
for (int i = 0; i < keys.size(); i++) {
Node *node = Object::cast_to<Node>(keys[i]);
for (const Variant &key : keys) {
Node *node = Object::cast_to<Node>(key);
Node3D *sp = Object::cast_to<Node3D>(node);
Dictionary d = snap_data[node];
Vector3 from = d["from"];
Expand All @@ -7903,8 +7904,8 @@ void Node3DEditor::_snap_selected_nodes_to_floor() {
undo_redo->create_action(TTR("Snap Nodes to Floor"));

// Perform snapping if at least one node can be snapped
for (int i = 0; i < keys.size(); i++) {
Node *node = Object::cast_to<Node>(keys[i]);
for (const Variant &key : keys) {
Node *node = Object::cast_to<Node>(key);
Node3D *sp = Object::cast_to<Node3D>(node);
Dictionary d = snap_data[node];
Vector3 from = d["from"];
Expand Down
12 changes: 6 additions & 6 deletions modules/gltf/editor/editor_import_blend_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ bpy.ops.export_scene.gltf(**opts['gltf_options'])

String dict_to_python(const Dictionary &p_dict) {
String entries;
Array dict_keys = p_dict.keys();
for (int i = 0; i < dict_keys.size(); i++) {
const String key = dict_keys[i];
List<Variant> dict_keys;
p_dict.get_key_list(&dict_keys);
for (const String key : dict_keys) {
String value;
Variant raw_value = p_dict[key];

Expand Down Expand Up @@ -127,9 +127,9 @@ String dict_to_python(const Dictionary &p_dict) {

String dict_to_xmlrpc(const Dictionary &p_dict) {
String members;
Array dict_keys = p_dict.keys();
for (int i = 0; i < dict_keys.size(); i++) {
const String key = dict_keys[i];
List<Variant> dict_keys;
p_dict.get_key_list(&dict_keys);
for (const String key : dict_keys) {
String value;
Variant raw_value = p_dict[key];

Expand Down
7 changes: 4 additions & 3 deletions modules/gltf/gltf_template_convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ static Dictionary to_dictionary(const HashMap<K, V> &p_inp) {
template <typename K, typename V>
static void set_from_dictionary(HashMap<K, V> &r_out, const Dictionary &p_inp) {
r_out.clear();
Array keys = p_inp.keys();
for (int i = 0; i < keys.size(); i++) {
r_out[keys[i]] = p_inp[keys[i]];
List<Variant> keys;
p_inp.get_key_list(&keys);
for (const Variant &key : keys) {
r_out[key] = p_inp[key];
}
}
} //namespace GLTFTemplateConvert
Expand Down
7 changes: 4 additions & 3 deletions modules/gltf/structures/gltf_skin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@ Dictionary GLTFSkin::get_joint_i_to_name() {

void GLTFSkin::set_joint_i_to_name(Dictionary p_joint_i_to_name) {
joint_i_to_name = HashMap<int, StringName>();
Array keys = p_joint_i_to_name.keys();
for (int i = 0; i < keys.size(); i++) {
joint_i_to_name[keys[i]] = p_joint_i_to_name[keys[i]];
List<Variant> keys;
p_joint_i_to_name.get_key_list(&keys);
for (const Variant &key : keys) {
joint_i_to_name[key] = p_joint_i_to_name[key];
}
}

Expand Down
6 changes: 3 additions & 3 deletions modules/openxr/editor/openxr_select_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ void OpenXRSelectRuntime::_update_items() {
set_item_metadata(index, "");
index++;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ HashMap<String, bool *> OpenXRExtensionWrapperExtension::get_requested_extension

if (GDVIRTUAL_CALL(_get_requested_extensions, request_extension)) {
HashMap<String, bool *> result;
Array keys = request_extension.keys();
for (int i = 0; i < keys.size(); i++) {
String key = keys.get(i);
List<Variant> keys;
request_extension.get_key_list(&keys);
for (const String key : keys) {
GDExtensionPtr<bool> value = VariantCaster<GDExtensionPtr<bool>>::cast(request_extension.get(key, GDExtensionPtr<bool>(nullptr)));
result.insert(key, value);
}
Expand Down
7 changes: 4 additions & 3 deletions scene/gui/code_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1227,9 +1227,10 @@ void CodeEdit::add_auto_brace_completion_pair(const String &p_open_key, const St
void CodeEdit::set_auto_brace_completion_pairs(const Dictionary &p_auto_brace_completion_pairs) {
auto_brace_completion_pairs.clear();

Array keys = p_auto_brace_completion_pairs.keys();
for (int i = 0; i < keys.size(); i++) {
add_auto_brace_completion_pair(keys[i], p_auto_brace_completion_pairs[keys[i]]);
List<Variant> keys;
p_auto_brace_completion_pairs.get_key_list(&keys);
for (const Variant &key : keys) {
add_auto_brace_completion_pair(key, p_auto_brace_completion_pairs[key]);
}
}

Expand Down

0 comments on commit 9ab9954

Please sign in to comment.