From 955d5affa857ec1f358c56da8fb1ff4ab6590704 Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Mon, 15 Apr 2024 15:18:34 +0200 Subject: [PATCH] Reduce and prevent unnecessary random-access to `List` Random-access access to `List` when iterating is `O(n^2)` (`O(n)` when accessing a single element) * Removed subscript operator, in favor of a more explicit `get` * Added conversion from `Iterator` to `ConstIterator` * Remade existing operations into other solutions when applicable --- core/debugger/debugger_marshalls.cpp | 8 +- core/debugger/remote_debugger.cpp | 3 +- core/debugger/remote_debugger_peer.cpp | 4 +- core/doc_data.cpp | 5 +- core/extension/extension_api_dump.cpp | 35 +- core/extension/gdextension.cpp | 11 +- core/io/ip.cpp | 16 +- core/io/udp_server.cpp | 2 +- core/object/class_db.cpp | 9 +- core/object/method_bind.h | 9 +- core/object/object.cpp | 5 +- core/templates/list.h | 62 +- drivers/unix/dir_access_unix.cpp | 2 +- drivers/unix/os_unix.cpp | 16 +- editor/animation_bezier_editor.cpp | 8 +- editor/animation_track_editor.cpp | 23 +- editor/connections_dialog.cpp | 7 +- .../debug_adapter/debug_adapter_parser.cpp | 5 +- .../debug_adapter/debug_adapter_protocol.cpp | 2 +- editor/debugger/editor_debugger_inspector.cpp | 6 +- editor/debugger/editor_debugger_tree.cpp | 13 +- editor/debugger/script_editor_debugger.cpp | 19 +- editor/doc_tools.cpp | 27 +- editor/editor_about.cpp | 5 +- editor/editor_audio_buses.cpp | 9 +- editor/editor_inspector.cpp | 8 +- editor/editor_node.cpp | 14 +- editor/editor_translation_parser.cpp | 16 +- editor/export/project_export.cpp | 10 +- editor/filesystem_dock.cpp | 10 +- editor/gui/scene_tree_editor.cpp | 6 +- editor/import/3d/resource_importer_scene.cpp | 6 +- editor/import/3d/scene_import_settings.cpp | 2 +- editor/inspector_dock.cpp | 6 +- .../animation_player_editor_plugin.cpp | 6 +- editor/plugins/canvas_item_editor_plugin.cpp | 108 ++-- editor/plugins/editor_debugger_plugin.cpp | 10 +- .../plugins/gizmos/joint_3d_gizmo_plugin.cpp | 2 +- editor/plugins/mesh_library_editor_plugin.cpp | 4 +- editor/plugins/node_3d_editor_gizmos.cpp | 10 +- editor/plugins/node_3d_editor_plugin.cpp | 12 +- .../resource_preloader_editor_plugin.cpp | 4 +- editor/plugins/script_editor_plugin.cpp | 4 +- editor/plugins/script_text_editor.cpp | 8 +- .../plugins/sprite_frames_editor_plugin.cpp | 16 +- editor/plugins/text_shader_editor.cpp | 4 +- .../plugins/version_control_editor_plugin.cpp | 42 +- .../plugins/visual_shader_editor_plugin.cpp | 26 +- editor/pot_generator.cpp | 4 +- editor/property_selector.cpp | 16 +- editor/rename_dialog.cpp | 8 +- editor/scene_tree_dock.cpp | 42 +- editor/shader_create_dialog.cpp | 13 +- main/main.cpp | 539 +++++++++--------- modules/enet/enet_multiplayer_peer.cpp | 4 +- modules/gdscript/gdscript_analyzer.cpp | 37 +- modules/gdscript/gdscript_compiler.cpp | 6 +- modules/gdscript/gdscript_editor.cpp | 30 +- .../gdscript/gdscript_utility_functions.cpp | 2 +- .../gdscript_extend_parser.cpp | 2 +- .../language_server/gdscript_workspace.cpp | 6 +- .../gdscript/tests/gdscript_test_runner.cpp | 4 +- .../tests/gdscript_test_runner_suite.h | 18 +- modules/gdscript/tests/test_gdscript.cpp | 6 +- modules/mono/class_db_api_json.cpp | 4 +- modules/mono/editor/bindings_generator.cpp | 35 +- .../multiplayer/scene_replication_config.cpp | 13 +- .../scene_replication_interface.cpp | 2 +- modules/openxr/openxr_api.cpp | 8 +- modules/webrtc/webrtc_multiplayer_peer.cpp | 22 +- .../remote_debugger_peer_websocket.cpp | 4 +- platform/android/export/export_plugin.cpp | 6 +- platform/android/java_godot_wrapper.cpp | 5 +- platform/ios/export/godot_plugin_config.cpp | 14 +- platform/linuxbsd/wayland/wayland_thread.cpp | 2 +- platform/web/os_web.cpp | 4 +- platform/windows/display_server_windows.cpp | 4 +- platform/windows/joypad_windows.cpp | 2 +- platform/windows/joypad_windows.h | 2 +- scene/2d/animated_sprite_2d.cpp | 2 +- scene/2d/tile_map_layer.cpp | 6 +- scene/3d/skeleton_3d.cpp | 2 +- scene/3d/sprite_3d.cpp | 2 +- .../animation_node_state_machine.cpp | 10 +- scene/animation/animation_tree.cpp | 6 +- scene/debugger/scene_debugger.cpp | 8 +- scene/gui/color_picker.cpp | 30 +- scene/main/node.cpp | 2 +- ...skeleton_modification_2d_physicalbones.cpp | 2 +- scene/resources/visual_shader.cpp | 54 +- .../visual_shader_particle_nodes.cpp | 6 +- servers/debugger/servers_debugger.cpp | 6 +- servers/rendering/renderer_rd/shader_rd.cpp | 4 +- servers/rendering/renderer_viewport.cpp | 2 +- servers/rendering/shader_compiler.cpp | 10 +- servers/rendering/shader_language.cpp | 28 +- servers/rendering/shader_types.cpp | 4 +- tests/core/object/test_class_db.h | 14 +- tests/core/object/test_object.h | 2 +- tests/core/os/test_os.h | 4 +- tests/core/variant/test_dictionary.h | 2 +- tests/scene/test_sprite_frames.h | 5 +- tests/test_main.cpp | 6 +- 103 files changed, 877 insertions(+), 849 deletions(-) diff --git a/core/debugger/debugger_marshalls.cpp b/core/debugger/debugger_marshalls.cpp index 3e6b7501c7e..f4283e0ea9c 100644 --- a/core/debugger/debugger_marshalls.cpp +++ b/core/debugger/debugger_marshalls.cpp @@ -38,10 +38,10 @@ Array DebuggerMarshalls::ScriptStackDump::serialize() { Array arr; arr.push_back(frames.size() * 3); - for (int i = 0; i < frames.size(); i++) { - arr.push_back(frames[i].file); - arr.push_back(frames[i].line); - arr.push_back(frames[i].func); + for (const ScriptLanguage::StackInfo &frame : frames) { + arr.push_back(frame.file); + arr.push_back(frame.line); + arr.push_back(frame.func); } return arr; } diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp index 1973663c729..bd30da3047d 100644 --- a/core/debugger/remote_debugger.cpp +++ b/core/debugger/remote_debugger.cpp @@ -206,8 +206,7 @@ void RemoteDebugger::flush_output() { Vector joined_log_strings; Vector strings; Vector types; - for (int i = 0; i < output_strings.size(); i++) { - const OutputString &output_string = output_strings[i]; + for (const OutputString &output_string : output_strings) { if (output_string.type == MESSAGE_TYPE_ERROR) { if (!joined_log_strings.is_empty()) { strings.push_back(String("\n").join(joined_log_strings)); diff --git a/core/debugger/remote_debugger_peer.cpp b/core/debugger/remote_debugger_peer.cpp index 81ee09f5151..21a9014626d 100644 --- a/core/debugger/remote_debugger_peer.cpp +++ b/core/debugger/remote_debugger_peer.cpp @@ -45,7 +45,7 @@ bool RemoteDebuggerPeerTCP::has_message() { Array RemoteDebuggerPeerTCP::get_message() { MutexLock lock(mutex); ERR_FAIL_COND_V(!has_message(), Array()); - Array out = in_queue[0]; + Array out = in_queue.front()->get(); in_queue.pop_front(); return out; } @@ -100,7 +100,7 @@ void RemoteDebuggerPeerTCP::_write_out() { break; // Nothing left to send } mutex.lock(); - Variant var = out_queue[0]; + Variant var = out_queue.front()->get(); out_queue.pop_front(); mutex.unlock(); int size = 0; diff --git a/core/doc_data.cpp b/core/doc_data.cpp index 7549ba884ea..672a36c35c1 100644 --- a/core/doc_data.cpp +++ b/core/doc_data.cpp @@ -152,9 +152,10 @@ void DocData::method_doc_from_methodinfo(DocData::MethodDoc &p_method, const Met return_doc_from_retinfo(p_method, p_methodinfo.return_val); - for (int i = 0; i < p_methodinfo.arguments.size(); i++) { + int i = 0; + for (List::ConstIterator itr = p_methodinfo.arguments.begin(); itr != p_methodinfo.arguments.end(); ++itr, ++i) { DocData::ArgumentDoc argument; - argument_doc_from_arginfo(argument, p_methodinfo.arguments[i]); + argument_doc_from_arginfo(argument, *itr); int default_arg_index = i - (p_methodinfo.arguments.size() - p_methodinfo.default_arguments.size()); if (default_arg_index >= 0) { Variant default_arg = p_methodinfo.default_arguments[default_arg_index]; diff --git a/core/extension/extension_api_dump.cpp b/core/extension/extension_api_dump.cpp index d7fba743652..1c9b4dc3e8e 100644 --- a/core/extension/extension_api_dump.cpp +++ b/core/extension/extension_api_dump.cpp @@ -1018,26 +1018,34 @@ Dictionary GDExtensionAPIDump::generate_extension_api(bool p_include_docs) { d2["is_virtual"] = true; // virtual functions have no hash since no MethodBind is involved bool has_return = mi.return_val.type != Variant::NIL || (mi.return_val.usage & PROPERTY_USAGE_NIL_IS_VARIANT); - Array arguments; - for (int i = (has_return ? -1 : 0); i < mi.arguments.size(); i++) { - PropertyInfo pinfo = i == -1 ? mi.return_val : mi.arguments[i]; + if (has_return) { + PropertyInfo pinfo = mi.return_val; Dictionary d3; - if (i >= 0) { - d3["name"] = pinfo.name; + d3["type"] = get_property_info_type_name(pinfo); + + if (mi.get_argument_meta(-1) > 0) { + d3["meta"] = get_type_meta_name((GodotTypeInfo::Metadata)mi.get_argument_meta(-1)); } + d2["return_value"] = d3; + } + + Array arguments; + int i = 0; + for (List::ConstIterator itr = mi.arguments.begin(); itr != mi.arguments.end(); ++itr, ++i) { + const PropertyInfo &pinfo = *itr; + Dictionary d3; + + d3["name"] = pinfo.name; + d3["type"] = get_property_info_type_name(pinfo); if (mi.get_argument_meta(i) > 0) { d3["meta"] = get_type_meta_name((GodotTypeInfo::Metadata)mi.get_argument_meta(i)); } - if (i == -1) { - d2["return_value"] = d3; - } else { - arguments.push_back(d3); - } + arguments.push_back(d3); } if (arguments.size()) { @@ -1151,10 +1159,11 @@ Dictionary GDExtensionAPIDump::generate_extension_api(bool p_include_docs) { Array arguments; - for (int i = 0; i < F.arguments.size(); i++) { + int i = 0; + for (List::ConstIterator itr = F.arguments.begin(); itr != F.arguments.end(); ++itr, ++i) { Dictionary d3; - d3["name"] = F.arguments[i].name; - d3["type"] = get_property_info_type_name(F.arguments[i]); + d3["name"] = itr->name; + d3["type"] = get_property_info_type_name(*itr); if (F.get_argument_meta(i) > 0) { d3["meta"] = get_type_meta_name((GodotTypeInfo::Metadata)F.get_argument_meta(i)); } diff --git a/core/extension/gdextension.cpp b/core/extension/gdextension.cpp index b48ea970400..a26bb3e8f3c 100644 --- a/core/extension/gdextension.cpp +++ b/core/extension/gdextension.cpp @@ -211,14 +211,14 @@ protected: if (p_arg < 0) { return return_value_info.type; } else { - return arguments_info[p_arg].type; + return arguments_info.get(p_arg).type; } } virtual PropertyInfo _gen_argument_type_info(int p_arg) const override { if (p_arg < 0) { return return_value_info; } else { - return arguments_info[p_arg]; + return arguments_info.get(p_arg); } } @@ -232,7 +232,7 @@ public: if (p_arg < 0) { return return_value_metadata; } else { - return arguments_metadata[p_arg]; + return arguments_metadata.get(p_arg); } } #endif @@ -319,8 +319,9 @@ public: return false; } - for (uint32_t i = 0; i < p_method_info->argument_count; i++) { - if (arguments_info[i].type != (Variant::Type)p_method_info->arguments_info[i].type) { + List::ConstIterator itr = arguments_info.begin(); + for (uint32_t i = 0; i < p_method_info->argument_count; ++itr, ++i) { + if (itr->type != (Variant::Type)p_method_info->arguments_info[i].type) { return false; } } diff --git a/core/io/ip.cpp b/core/io/ip.cpp index ec861049264..f20d65bef90 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -148,8 +148,8 @@ PackedStringArray IP::resolve_hostname_addresses(const String &p_hostname, Type resolver->mutex.unlock(); PackedStringArray result; - for (int i = 0; i < res.size(); ++i) { - result.push_back(String(res[i])); + for (const IPAddress &E : res) { + result.push_back(String(E)); } return result; } @@ -206,9 +206,9 @@ IPAddress IP::get_resolve_item_address(ResolverID p_id) const { List res = resolver->queue[p_id].response; - for (int i = 0; i < res.size(); ++i) { - if (res[i].is_valid()) { - return res[i]; + for (const IPAddress &E : res) { + if (E.is_valid()) { + return E; } } return IPAddress(); @@ -226,9 +226,9 @@ Array IP::get_resolve_item_addresses(ResolverID p_id) const { List res = resolver->queue[p_id].response; Array result; - for (int i = 0; i < res.size(); ++i) { - if (res[i].is_valid()) { - result.push_back(String(res[i])); + for (const IPAddress &E : res) { + if (E.is_valid()) { + result.push_back(String(E)); } } return result; diff --git a/core/io/udp_server.cpp b/core/io/udp_server.cpp index 215c6903a65..75ba784dbd1 100644 --- a/core/io/udp_server.cpp +++ b/core/io/udp_server.cpp @@ -161,7 +161,7 @@ Ref UDPServer::take_connection() { return conn; } - Peer peer = pending[0]; + Peer peer = pending.front()->get(); pending.pop_front(); peers.push_back(peer); return peer.peer; diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index 876635529c5..6b84dfcee9b 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -425,8 +425,8 @@ uint32_t ClassDB::get_api_hash(APIType p_api) { for (const StringName &F : snames) { MethodInfo &mi = t->signal_map[F]; hash = hash_murmur3_one_64(F.hash(), hash); - for (int i = 0; i < mi.arguments.size(); i++) { - hash = hash_murmur3_one_64(mi.arguments[i].type, hash); + for (const PropertyInfo &pi : mi.arguments) { + hash = hash_murmur3_one_64(pi.type, hash); } } } @@ -1856,8 +1856,9 @@ void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_ if (p_arg_names.size() != mi.arguments.size()) { WARN_PRINT("Mismatch argument name count for virtual method: " + String(p_class) + "::" + p_method.name); } else { - for (int i = 0; i < p_arg_names.size(); i++) { - mi.arguments[i].name = p_arg_names[i]; + List::Iterator itr = mi.arguments.begin(); + for (int i = 0; i < p_arg_names.size(); ++itr, ++i) { + itr->name = p_arg_names[i]; } } } diff --git a/core/object/method_bind.h b/core/object/method_bind.h index e97f4abc6a2..2f9a2d1679b 100644 --- a/core/object/method_bind.h +++ b/core/object/method_bind.h @@ -152,7 +152,7 @@ public: if (p_arg < 0) { return _gen_return_type_info(); } else if (p_arg < method_info.arguments.size()) { - return method_info.arguments[p_arg]; + return method_info.arguments.get(p_arg); } else { return PropertyInfo(Variant::NIL, "arg_" + itos(p_arg), PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT); } @@ -193,10 +193,11 @@ public: Vector names; names.resize(method_info.arguments.size()); #endif - for (int i = 0; i < method_info.arguments.size(); i++) { - at[i + 1] = method_info.arguments[i].type; + int i = 0; + for (List::ConstIterator itr = method_info.arguments.begin(); itr != method_info.arguments.end(); ++itr, ++i) { + at[i + 1] = itr->type; #ifdef DEBUG_METHODS_ENABLED - names.write[i] = method_info.arguments[i].name; + names.write[i] = itr->name; #endif } diff --git a/core/object/object.cpp b/core/object/object.cpp index b6c8a87a222..ab89f96a0de 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -1302,9 +1302,8 @@ TypedArray Object::_get_signal_connection_list(const StringName &p_s TypedArray Object::_get_incoming_connections() const { TypedArray ret; - int connections_amount = connections.size(); - for (int idx_conn = 0; idx_conn < connections_amount; idx_conn++) { - ret.push_back(connections[idx_conn]); + for (const Object::Connection &connection : connections) { + ret.push_back(connection); } return ret; diff --git a/core/templates/list.h b/core/templates/list.h index b4d4beb9300..6663f06c309 100644 --- a/core/templates/list.h +++ b/core/templates/list.h @@ -139,31 +139,6 @@ public: typedef T ValueType; - struct Iterator { - _FORCE_INLINE_ T &operator*() const { - return E->get(); - } - _FORCE_INLINE_ T *operator->() const { return &E->get(); } - _FORCE_INLINE_ Iterator &operator++() { - E = E->next(); - return *this; - } - _FORCE_INLINE_ Iterator &operator--() { - E = E->prev(); - return *this; - } - - _FORCE_INLINE_ bool operator==(const Iterator &b) const { return E == b.E; } - _FORCE_INLINE_ bool operator!=(const Iterator &b) const { return E != b.E; } - - Iterator(Element *p_E) { E = p_E; } - Iterator() {} - Iterator(const Iterator &p_it) { E = p_it.E; } - - private: - Element *E = nullptr; - }; - struct ConstIterator { _FORCE_INLINE_ const T &operator*() const { return E->get(); @@ -189,6 +164,35 @@ public: const Element *E = nullptr; }; + struct Iterator { + _FORCE_INLINE_ T &operator*() const { + return E->get(); + } + _FORCE_INLINE_ T *operator->() const { return &E->get(); } + _FORCE_INLINE_ Iterator &operator++() { + E = E->next(); + return *this; + } + _FORCE_INLINE_ Iterator &operator--() { + E = E->prev(); + return *this; + } + + _FORCE_INLINE_ bool operator==(const Iterator &b) const { return E == b.E; } + _FORCE_INLINE_ bool operator!=(const Iterator &b) const { return E != b.E; } + + Iterator(Element *p_E) { E = p_E; } + Iterator() {} + Iterator(const Iterator &p_it) { E = p_it.E; } + + operator ConstIterator() const { + return ConstIterator(E); + } + + private: + Element *E = nullptr; + }; + _FORCE_INLINE_ Iterator begin() { return Iterator(front()); } @@ -519,7 +523,9 @@ public: } } - T &operator[](int p_index) { + // Random access to elements, use with care, + // do not use for iteration. + T &get(int p_index) { CRASH_BAD_INDEX(p_index, size()); Element *I = front(); @@ -532,7 +538,9 @@ public: return I->get(); } - const T &operator[](int p_index) const { + // Random access to elements, use with care, + // do not use for iteration. + const T &get(int p_index) const { CRASH_BAD_INDEX(p_index, size()); const Element *I = front(); diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp index 2a85a81b91f..a4208829b7d 100644 --- a/drivers/unix/dir_access_unix.cpp +++ b/drivers/unix/dir_access_unix.cpp @@ -289,7 +289,7 @@ String DirAccessUnix::get_drive(int p_drive) { ERR_FAIL_INDEX_V(p_drive, list.size(), ""); - return list[p_drive]; + return list.get(p_drive); } int DirAccessUnix::get_current_drive() { diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 0a79c8014be..ce2553456d9 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -546,8 +546,8 @@ Dictionary OS_Unix::execute_with_pipe(const String &p_path, const List & // The child process. Vector cs; cs.push_back(p_path.utf8()); - for (int i = 0; i < p_arguments.size(); i++) { - cs.push_back(p_arguments[i].utf8()); + for (const String &arg : p_arguments) { + cs.push_back(arg.utf8()); } Vector args; @@ -606,8 +606,8 @@ Error OS_Unix::execute(const String &p_path, const List &p_arguments, St #else if (r_pipe) { String command = "\"" + p_path + "\""; - for (int i = 0; i < p_arguments.size(); i++) { - command += String(" \"") + p_arguments[i] + "\""; + for (const String &arg : p_arguments) { + command += String(" \"") + arg + "\""; } if (read_stderr) { command += " 2>&1"; // Include stderr @@ -647,8 +647,8 @@ Error OS_Unix::execute(const String &p_path, const List &p_arguments, St // The child process Vector cs; cs.push_back(p_path.utf8()); - for (int i = 0; i < p_arguments.size(); i++) { - cs.push_back(p_arguments[i].utf8()); + for (const String &arg : p_arguments) { + cs.push_back(arg.utf8()); } Vector args; @@ -689,8 +689,8 @@ Error OS_Unix::create_process(const String &p_path, const List &p_argume Vector cs; cs.push_back(p_path.utf8()); - for (int i = 0; i < p_arguments.size(); i++) { - cs.push_back(p_arguments[i].utf8()); + for (const String &arg : p_arguments) { + cs.push_back(arg.utf8()); } Vector args; diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index a16446aea6f..af4b759c7a3 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -1397,8 +1397,10 @@ void AnimationBezierTrackEdit::gui_input(const Ref &p_event) { } // 6-(undo) reinsert overlapped keys - for (int i = 0; i < to_restore.size(); i++) { - const AnimMoveRestore &amr = to_restore[i]; + List::ConstIterator restore_itr = to_restore.begin(); + List::ConstIterator handle_itr = to_restore_handle_modes.begin(); + for (; restore_itr != to_restore.end() && handle_itr != to_restore_handle_modes.end(); ++restore_itr, ++handle_itr) { + const AnimMoveRestore &amr = *restore_itr; Array key = amr.key; undo_redo->add_undo_method(animation.ptr(), "track_insert_key", amr.track, amr.time, amr.key, 1); undo_redo->add_undo_method( @@ -1409,7 +1411,7 @@ void AnimationBezierTrackEdit::gui_input(const Ref &p_event) { key[0], Vector2(key[1], key[2]), Vector2(key[3], key[4]), - to_restore_handle_modes[i]); + *handle_itr); } undo_redo->add_do_method(this, "_clear_selection_for_anim", animation); diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 88e0878bd4d..7dca019eff6 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -694,7 +694,7 @@ void AnimationMultiTrackKeyEdit::_key_ofs_changed(const Ref &p_anim, } int track = E.key; - key_ofs_map[track][key] = to; + key_ofs_map[track].get(key) = to; if (setting) { return; @@ -3803,8 +3803,8 @@ void AnimationTrackEditor::commit_insert_queue() { reset_allowed = false; } else { bool some_resettable = false; - for (int i = 0; i < insert_data.size(); i++) { - if (track_type_is_resettable(insert_data[i].type)) { + for (const AnimationTrackEditor::InsertData &E : insert_data) { + if (track_type_is_resettable(E.type)) { some_resettable = true; break; } @@ -3818,21 +3818,21 @@ void AnimationTrackEditor::commit_insert_queue() { int num_tracks = 0; String last_track_query; bool all_bezier = true; - for (int i = 0; i < insert_data.size(); i++) { - if (insert_data[i].type != Animation::TYPE_VALUE && insert_data[i].type != Animation::TYPE_BEZIER) { + for (const AnimationTrackEditor::InsertData &E : insert_data) { + if (E.type != Animation::TYPE_VALUE && E.type != Animation::TYPE_BEZIER) { all_bezier = false; } - if (insert_data[i].track_idx == -1) { + if (E.track_idx == -1) { ++num_tracks; - last_track_query = insert_data[i].query; + last_track_query = E.query; } - if (insert_data[i].type != Animation::TYPE_VALUE) { + if (E.type != Animation::TYPE_VALUE) { continue; } - switch (insert_data[i].value.get_type()) { + switch (E.value.get_type()) { case Variant::INT: case Variant::FLOAT: case Variant::VECTOR2: @@ -5317,14 +5317,15 @@ void AnimationTrackEditor::_add_method_key(const String &p_method) { Array params; int first_defarg = E.arguments.size() - E.default_arguments.size(); - for (int i = 0; i < E.arguments.size(); i++) { + int i = 0; + for (List::ConstIterator itr = E.arguments.begin(); itr != E.arguments.end(); ++itr, ++i) { if (i >= first_defarg) { Variant arg = E.default_arguments[i - first_defarg]; params.push_back(arg); } else { Callable::CallError ce; Variant arg; - Variant::construct(E.arguments[i].type, arg, nullptr, 0, ce); + Variant::construct(itr->type, arg, nullptr, 0, ce); params.push_back(arg); } } diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp index f57e9cb5f84..7714749b665 100644 --- a/editor/connections_dialog.cpp +++ b/editor/connections_dialog.cpp @@ -529,12 +529,13 @@ String ConnectDialog::get_signature(const MethodInfo &p_method, PackedStringArra signature.append(p_method.name); signature.append("("); - for (int i = 0; i < p_method.arguments.size(); i++) { - if (i > 0) { + int i = 0; + for (List::ConstIterator itr = p_method.arguments.begin(); itr != p_method.arguments.end(); ++itr, ++i) { + if (itr != p_method.arguments.begin()) { signature.append(", "); } - const PropertyInfo &pi = p_method.arguments[i]; + const PropertyInfo &pi = *itr; String type_name; switch (pi.type) { case Variant::NIL: diff --git a/editor/debugger/debug_adapter/debug_adapter_parser.cpp b/editor/debugger/debug_adapter/debug_adapter_parser.cpp index b75e5c1c0d3..3c0420d2f02 100644 --- a/editor/debugger/debug_adapter/debug_adapter_parser.cpp +++ b/editor/debugger/debug_adapter/debug_adapter_parser.cpp @@ -407,9 +407,10 @@ Dictionary DebugAdapterParser::req_scopes(const Dictionary &p_params) const { HashMap, DAP::StackFrame>::Iterator E = DebugAdapterProtocol::get_singleton()->stackframe_list.find(frame); if (E) { ERR_FAIL_COND_V(E->value.size() != 3, prepare_error_response(p_params, DAP::ErrorType::UNKNOWN)); - for (int i = 0; i < 3; i++) { + List::ConstIterator itr = E->value.begin(); + for (int i = 0; i < 3; ++itr, ++i) { DAP::Scope scope; - scope.variablesReference = E->value[i]; + scope.variablesReference = *itr; switch (i) { case 0: scope.name = "Locals"; diff --git a/editor/debugger/debug_adapter/debug_adapter_protocol.cpp b/editor/debugger/debug_adapter/debug_adapter_protocol.cpp index c86ca7aaad5..56cb3b6c736 100644 --- a/editor/debugger/debug_adapter/debug_adapter_protocol.cpp +++ b/editor/debugger/debug_adapter/debug_adapter_protocol.cpp @@ -967,7 +967,7 @@ void DebugAdapterProtocol::on_debug_stack_frame_var(const Array &p_data) { List scope_ids = stackframe_list.find(frame)->value; ERR_FAIL_COND(scope_ids.size() != 3); ERR_FAIL_INDEX(stack_var.type, 3); - int var_id = scope_ids[stack_var.type]; + int var_id = scope_ids.get(stack_var.type); DAP::Variable variable; diff --git a/editor/debugger/editor_debugger_inspector.cpp b/editor/debugger/editor_debugger_inspector.cpp index b2fd84d2edd..816bd6b72c3 100644 --- a/editor/debugger/editor_debugger_inspector.cpp +++ b/editor/debugger/editor_debugger_inspector.cpp @@ -146,9 +146,9 @@ ObjectID EditorDebuggerInspector::add_object(const Array &p_arr) { debug_obj->prop_list.clear(); int new_props_added = 0; HashSet changed; - for (int i = 0; i < obj.properties.size(); i++) { - PropertyInfo &pinfo = obj.properties[i].first; - Variant &var = obj.properties[i].second; + for (SceneDebuggerObject::SceneDebuggerProperty &property : obj.properties) { + PropertyInfo &pinfo = property.first; + Variant &var = property.second; if (pinfo.type == Variant::OBJECT) { if (var.get_type() == Variant::STRING) { diff --git a/editor/debugger/editor_debugger_tree.cpp b/editor/debugger/editor_debugger_tree.cpp index de2e51ee810..63053d2574d 100644 --- a/editor/debugger/editor_debugger_tree.cpp +++ b/editor/debugger/editor_debugger_tree.cpp @@ -147,17 +147,16 @@ void EditorDebuggerTree::update_scene_tree(const SceneDebuggerTree *p_tree, int // Nodes are in a flatten list, depth first. Use a stack of parents, avoid recursion. List> parents; - for (int i = 0; i < p_tree->nodes.size(); i++) { + for (const SceneDebuggerTree::RemoteNode &node : p_tree->nodes) { TreeItem *parent = nullptr; if (parents.size()) { // Find last parent. - Pair &p = parents[0]; + Pair &p = parents.front()->get(); parent = p.first; if (!(--p.second)) { // If no child left, remove it. parents.pop_front(); } } // Add this node. - const SceneDebuggerTree::RemoteNode &node = p_tree->nodes[i]; TreeItem *item = create_item(parent); item->set_text(0, node.name); if (node.scene_file_path.is_empty()) { @@ -244,8 +243,8 @@ void EditorDebuggerTree::update_scene_tree(const SceneDebuggerTree *p_tree, int item = parent; parent = item->get_parent(); // Check if parent expects more children. - for (int j = 0; j < parents.size(); j++) { - if (parents[j].first == item) { + for (const Pair &pair : parents) { + if (pair.first == item) { parent = nullptr; break; // Might have more children. } @@ -326,8 +325,8 @@ void EditorDebuggerTree::_item_menu_id_pressed(int p_option) { Ref sd = memnew(PackedScene); ResourceSaver::get_recognized_extensions(sd, &extensions); file_dialog->clear_filters(); - for (int i = 0; i < extensions.size(); i++) { - file_dialog->add_filter("*." + extensions[i], extensions[i].to_upper()); + for (const String &extension : extensions) { + file_dialog->add_filter("*." + extension, extension.to_upper()); } String filename = get_selected_path().get_file() + "." + extensions.front()->get().to_lower(); diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index 2b880274f88..d5cf887a4e9 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -440,13 +440,14 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, uint64_t p_thread Array stack_dump_info; - for (int i = 0; i < stack.frames.size(); i++) { + int i = 0; + for (List::Iterator itr = stack.frames.begin(); itr != stack.frames.end(); ++itr, ++i) { TreeItem *s = stack_dump->create_item(r); Dictionary d; d["frame"] = i; - d["file"] = stack.frames[i].file; - d["function"] = stack.frames[i].func; - d["line"] = stack.frames[i].line; + d["file"] = itr->file; + d["function"] = itr->func; + d["line"] = itr->line; stack_dump_info.push_back(d); s->set_metadata(0, d); @@ -725,20 +726,20 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, uint64_t p_thread metric.categories.push_back(frame_time); } - for (int i = 0; i < frame.servers.size(); i++) { - const ServersDebugger::ServerInfo &srv = frame.servers[i]; + for (const ServersDebugger::ServerInfo &srv : frame.servers) { EditorProfiler::Metric::Category c; const String name = srv.name; c.name = EditorPropertyNameProcessor::get_singleton()->process_name(name, EditorPropertyNameProcessor::STYLE_CAPITALIZED); c.items.resize(srv.functions.size()); c.total_time = 0; c.signature = "categ::" + name; - for (int j = 0; j < srv.functions.size(); j++) { + int j = 0; + for (List::ConstIterator itr = srv.functions.begin(); itr != srv.functions.end(); ++itr, ++j) { EditorProfiler::Metric::Category::Item item; item.calls = 1; item.line = 0; - item.name = srv.functions[j].name; - item.self = srv.functions[j].time; + item.name = itr->name; + item.self = itr->time; item.total = item.self; item.signature = "categ::" + name + "::" + item.name; item.name = EditorPropertyNameProcessor::get_singleton()->process_name(item.name, EditorPropertyNameProcessor::STYLE_CAPITALIZED); diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp index db45478d215..d3875709ee4 100644 --- a/editor/doc_tools.cpp +++ b/editor/doc_tools.cpp @@ -476,10 +476,10 @@ void DocTools::generate(BitField p_flags) { ResourceImporter *resimp = Object::cast_to(ClassDB::instantiate(name)); List options; resimp->get_import_options("", &options); - for (int i = 0; i < options.size(); i++) { - const PropertyInfo &prop = options[i].option; + for (const ResourceImporter::ImportOption &option : options) { + const PropertyInfo &prop = option.option; properties.push_back(prop); - import_options_default[prop.name] = options[i].default_value; + import_options_default[prop.name] = option.default_value; } own_properties = properties; memdelete(resimp); @@ -665,8 +665,8 @@ void DocTools::generate(BitField p_flags) { for (List::Element *EV = signal_list.front(); EV; EV = EV->next()) { DocData::MethodDoc signal; signal.name = EV->get().name; - for (int i = 0; i < EV->get().arguments.size(); i++) { - const PropertyInfo &arginfo = EV->get().arguments[i]; + for (List::Element *EA = EV->get().arguments.front(); EA; EA = EA->next()) { + const PropertyInfo &arginfo = EA->get(); DocData::ArgumentDoc argument; DocData::argument_doc_from_arginfo(argument, arginfo); @@ -857,10 +857,11 @@ void DocTools::generate(BitField p_flags) { method.name = mi.name; - for (int j = 0; j < mi.arguments.size(); j++) { - PropertyInfo arginfo = mi.arguments[j]; + int j = 0; + for (List::ConstIterator itr = mi.arguments.begin(); itr != mi.arguments.end(); ++itr, ++j) { + PropertyInfo arginfo = *itr; DocData::ArgumentDoc ad; - DocData::argument_doc_from_arginfo(ad, mi.arguments[j]); + DocData::argument_doc_from_arginfo(ad, arginfo); ad.name = arginfo.name; int darg_idx = mi.default_arguments.size() - mi.arguments.size() + j; @@ -1047,9 +1048,10 @@ void DocTools::generate(BitField p_flags) { DocData::return_doc_from_retinfo(md, mi.return_val); - for (int j = 0; j < mi.arguments.size(); j++) { + int j = 0; + for (List::ConstIterator itr = mi.arguments.begin(); itr != mi.arguments.end(); ++itr, ++j) { DocData::ArgumentDoc ad; - DocData::argument_doc_from_arginfo(ad, mi.arguments[j]); + DocData::argument_doc_from_arginfo(ad, *itr); int darg_idx = j - (mi.arguments.size() - mi.default_arguments.size()); if (darg_idx >= 0) { @@ -1091,9 +1093,10 @@ void DocTools::generate(BitField p_flags) { DocData::return_doc_from_retinfo(atd, ai.return_val); - for (int j = 0; j < ai.arguments.size(); j++) { + int j = 0; + for (List::ConstIterator itr = ai.arguments.begin(); itr != ai.arguments.end(); ++itr, ++j) { DocData::ArgumentDoc ad; - DocData::argument_doc_from_arginfo(ad, ai.arguments[j]); + DocData::argument_doc_from_arginfo(ad, *itr); int darg_idx = j - (ai.arguments.size() - ai.default_arguments.size()); if (darg_idx >= 0) { diff --git a/editor/editor_about.cpp b/editor/editor_about.cpp index af0419a81a6..af4631a539a 100644 --- a/editor/editor_about.cpp +++ b/editor/editor_about.cpp @@ -107,13 +107,14 @@ ScrollContainer *EditorAbout::_populate_list(const String &p_name, const List empty_stylebox = memnew(StyleBoxEmpty); - for (int i = 0; i < p_sections.size(); i++) { + int i = 0; + for (List::ConstIterator itr = p_sections.begin(); itr != p_sections.end(); ++itr, ++i) { bool single_column = p_single_column_flags & (1 << i); const char *const *names_ptr = p_src[i]; if (*names_ptr) { Label *lbl = memnew(Label); lbl->set_theme_type_variation("HeaderSmall"); - lbl->set_text(p_sections[i]); + lbl->set_text(*itr); vbc->add_child(lbl); ItemList *il = memnew(ItemList); diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index 658bc33ddc0..e20d046e00b 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -1426,9 +1426,9 @@ Size2 EditorAudioMeterNotches::get_minimum_size() const { float width = 0; float height = top_padding + btm_padding; - for (int i = 0; i < notches.size(); i++) { - if (notches[i].render_db_value) { - width = MAX(width, font->get_string_size(String::num(Math::abs(notches[i].db_value)) + "dB", HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x); + for (const EditorAudioMeterNotches::AudioNotch ¬ch : notches) { + if (notch.render_db_value) { + width = MAX(width, font->get_string_size(String::num(Math::abs(notch.db_value)) + "dB", HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x); height += font_height; } } @@ -1462,8 +1462,7 @@ void EditorAudioMeterNotches::_notification(int p_what) { void EditorAudioMeterNotches::_draw_audio_notches() { float font_height = theme_cache.font->get_height(theme_cache.font_size); - for (int i = 0; i < notches.size(); i++) { - AudioNotch n = notches[i]; + for (const AudioNotch &n : notches) { draw_line(Vector2(0, (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + top_padding), Vector2(line_length * EDSCALE, (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + top_padding), theme_cache.notch_color, diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 845ca9b26d7..dd9805085b3 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -2563,16 +2563,16 @@ EditorProperty *EditorInspector::instantiate_property_editor(Object *p_object, c for (int i = inspector_plugin_count - 1; i >= 0; i--) { inspector_plugins[i]->parse_property(p_object, p_type, p_path, p_hint, p_hint_text, p_usage, p_wide); if (inspector_plugins[i]->added_editors.size()) { - for (int j = 1; j < inspector_plugins[i]->added_editors.size(); j++) { //only keep first one - memdelete(inspector_plugins[i]->added_editors[j].property_editor); + for (List::Element *E = inspector_plugins[i]->added_editors.front()->next(); E; E = E->next()) { //only keep first one + memdelete(E->get().property_editor); } - EditorProperty *prop = Object::cast_to(inspector_plugins[i]->added_editors[0].property_editor); + EditorProperty *prop = Object::cast_to(inspector_plugins[i]->added_editors.front()->get().property_editor); if (prop) { inspector_plugins[i]->added_editors.clear(); return prop; } else { - memdelete(inspector_plugins[i]->added_editors[0].property_editor); + memdelete(inspector_plugins[i]->added_editors.front()->get().property_editor); inspector_plugins[i]->added_editors.clear(); } } diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 5bb9aa91d26..33b46b82bc9 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -2603,8 +2603,8 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { List extensions; ResourceLoader::get_recognized_extensions_for_type("PackedScene", &extensions); file->clear_filters(); - for (int i = 0; i < extensions.size(); i++) { - file->add_filter("*." + extensions[i], extensions[i].to_upper()); + for (const String &extension : extensions) { + file->add_filter("*." + extension, extension.to_upper()); } Node *scene = editor_data.get_edited_scene_root(); @@ -2722,8 +2722,8 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { Ref sd = memnew(PackedScene); ResourceSaver::get_recognized_extensions(sd, &extensions); file->clear_filters(); - for (int i = 0; i < extensions.size(); i++) { - file->add_filter("*." + extensions[i], extensions[i].to_upper()); + for (const String &extension : extensions) { + file->add_filter("*." + extension, extension.to_upper()); } if (!scene->get_scene_file_path().is_empty()) { @@ -3054,14 +3054,14 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { List extensions; ResourceLoader::get_recognized_extensions_for_type("PackedScene", &extensions); file->clear_filters(); - for (int i = 0; i < extensions.size(); i++) { - file->add_filter("*." + extensions[i], extensions[i].to_upper()); + for (const String &extension : extensions) { + file->add_filter("*." + extension, extension.to_upper()); } Node *scene = editor_data.get_edited_scene_root(); if (scene) { file->set_current_path(scene->get_scene_file_path()); - }; + } file->set_title(TTR("Pick a Main Scene")); file->popup_file_dialog(); diff --git a/editor/editor_translation_parser.cpp b/editor/editor_translation_parser.cpp index 813d7c486fe..8a77ce4a82f 100644 --- a/editor/editor_translation_parser.cpp +++ b/editor/editor_translation_parser.cpp @@ -93,8 +93,8 @@ void EditorTranslationParser::get_recognized_extensions(List *r_extensio custom_parsers[i]->get_recognized_extensions(&temp); } // Remove duplicates. - for (int i = 0; i < temp.size(); i++) { - extensions.insert(temp[i]); + for (const String &E : temp) { + extensions.insert(E); } for (const String &E : extensions) { r_extensions->push_back(E); @@ -104,8 +104,8 @@ void EditorTranslationParser::get_recognized_extensions(List *r_extensio bool EditorTranslationParser::can_parse(const String &p_extension) const { List extensions; get_recognized_extensions(&extensions); - for (int i = 0; i < extensions.size(); i++) { - if (p_extension == extensions[i]) { + for (const String &extension : extensions) { + if (p_extension == extension) { return true; } } @@ -117,8 +117,8 @@ Ref EditorTranslationParser::get_parser(const Str for (int i = 0; i < custom_parsers.size(); i++) { List temp; custom_parsers[i]->get_recognized_extensions(&temp); - for (int j = 0; j < temp.size(); j++) { - if (temp[j] == p_extension) { + for (const String &E : temp) { + if (E == p_extension) { return custom_parsers[i]; } } @@ -127,8 +127,8 @@ Ref EditorTranslationParser::get_parser(const Str for (int i = 0; i < standard_parsers.size(); i++) { List temp; standard_parsers[i]->get_recognized_extensions(&temp); - for (int j = 0; j < temp.size(); j++) { - if (temp[j] == p_extension) { + for (const String &E : temp) { + if (E == p_extension) { return standard_parsers[i]; } } diff --git a/editor/export/project_export.cpp b/editor/export/project_export.cpp index c995e590f1e..1da75ff88f2 100644 --- a/editor/export/project_export.cpp +++ b/editor/export/project_export.cpp @@ -270,8 +270,8 @@ void ProjectExportDialog::_edit_preset(int p_index) { List extension_list = current->get_platform()->get_binary_extensions(current); Vector extension_vector; - for (int i = 0; i < extension_list.size(); i++) { - extension_vector.push_back("*." + extension_list[i]); + for (const String &extension : extension_list) { + extension_vector.push_back("*." + extension); } export_path->setup(extension_vector, false, true); @@ -1089,16 +1089,16 @@ void ProjectExportDialog::_export_project() { export_project->clear_filters(); List extension_list = platform->get_binary_extensions(current); - for (int i = 0; i < extension_list.size(); i++) { + for (const String &extension : extension_list) { // TRANSLATORS: This is the name of a project export file format. %s will be replaced by the platform name. - export_project->add_filter("*." + extension_list[i], vformat(TTR("%s Export"), platform->get_name())); + export_project->add_filter("*." + extension, vformat(TTR("%s Export"), platform->get_name())); } if (!current->get_export_path().is_empty()) { export_project->set_current_path(current->get_export_path()); } else { if (extension_list.size() >= 1) { - export_project->set_current_file(default_filename + "." + extension_list[0]); + export_project->set_current_file(default_filename + "." + extension_list.front()->get()); } else { export_project->set_current_file(default_filename); } diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index ac4991755b7..674b20480d4 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -2268,11 +2268,11 @@ void FileSystemDock::_file_option(int p_option, const Vector &p_selected } const bool is_directory = fpath.ends_with("/"); - for (int i = 0; i < terminal_emulator_args.size(); i++) { + for (String &terminal_emulator_arg : terminal_emulator_args) { if (is_directory) { - terminal_emulator_args[i] = terminal_emulator_args[i].replace("{directory}", ProjectSettings::get_singleton()->globalize_path(fpath)); + terminal_emulator_arg = terminal_emulator_arg.replace("{directory}", ProjectSettings::get_singleton()->globalize_path(fpath)); } else { - terminal_emulator_args[i] = terminal_emulator_args[i].replace("{directory}", ProjectSettings::get_singleton()->globalize_path(fpath).get_base_dir()); + terminal_emulator_arg = terminal_emulator_arg.replace("{directory}", ProjectSettings::get_singleton()->globalize_path(fpath).get_base_dir()); } } @@ -2288,8 +2288,8 @@ void FileSystemDock::_file_option(int p_option, const Vector &p_selected const Error err = OS::get_singleton()->create_process(chosen_terminal_emulator, terminal_emulator_args, nullptr, true); if (err != OK) { String args_string; - for (int i = 0; i < terminal_emulator_args.size(); i++) { - args_string += terminal_emulator_args[i]; + for (const String &terminal_emulator_arg : terminal_emulator_args) { + args_string += terminal_emulator_arg; } ERR_PRINT_ED(vformat(TTR("Couldn't run external terminal program (error code %d): %s %s\nCheck `filesystem/external_programs/terminal_emulator` and `filesystem/external_programs/terminal_emulator_flags` in the Editor Settings."), err, chosen_terminal_emulator, args_string)); } diff --git a/editor/gui/scene_tree_editor.cpp b/editor/gui/scene_tree_editor.cpp index 361ae2a9459..7d2a3c1e240 100644 --- a/editor/gui/scene_tree_editor.cpp +++ b/editor/gui/scene_tree_editor.cpp @@ -755,11 +755,11 @@ bool SceneTreeEditor::_item_matches_all_terms(TreeItem *p_item, const PackedStri node->get_groups(&group_info_list); bool term_in_groups = false; - for (int j = 0; j < group_info_list.size(); j++) { - if (!group_info_list[j].persistent) { + for (const Node::GroupInfo &group_info : group_info_list) { + if (!group_info.persistent) { continue; // Ignore internal groups. } - if (String(group_info_list[j].name).to_lower().contains(argument)) { + if (String(group_info.name).to_lower().contains(argument)) { term_in_groups = true; break; } diff --git a/editor/import/3d/resource_importer_scene.cpp b/editor/import/3d/resource_importer_scene.cpp index bb833b1b2c1..707be843811 100644 --- a/editor/import/3d/resource_importer_scene.cpp +++ b/editor/import/3d/resource_importer_scene.cpp @@ -1392,7 +1392,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, HashMap< List anim_list; anim_player->get_animation_list(&anim_list); if (anim_list.size() == 1) { - selected_animation_name = anim_list[0]; + selected_animation_name = anim_list.front()->get(); } rest_animation = anim_player->get_animation(selected_animation_name); if (rest_animation.is_valid()) { @@ -1408,7 +1408,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, HashMap< List anim_list; library->get_animation_list(&anim_list); if (anim_list.size() == 1) { - selected_animation_name = String(anim_list[0]); + selected_animation_name = String(anim_list.front()->get()); } rest_animation = library->get_animation(selected_animation_name); } @@ -2203,7 +2203,7 @@ bool ResourceImporterScene::get_internal_option_visibility(InternalImportCategor List anim_list; library->get_animation_list(&anim_list); if (anim_list.size() == 1) { - selected_animation_name = String(anim_list[0]); + selected_animation_name = String(anim_list.front()->get()); } if (library->has_animation(selected_animation_name)) { anim = library->get_animation(selected_animation_name); diff --git a/editor/import/3d/scene_import_settings.cpp b/editor/import/3d/scene_import_settings.cpp index 325525be1b6..08e52ddbe14 100644 --- a/editor/import/3d/scene_import_settings.cpp +++ b/editor/import/3d/scene_import_settings.cpp @@ -144,7 +144,7 @@ class SceneImportSettingsData : public Object { List anim_names; library->get_animation_list(&anim_names); if (anim_names.size() == 1) { - (*settings)["rest_pose/selected_animation"] = String(anim_names[0]); + (*settings)["rest_pose/selected_animation"] = String(anim_names.front()->get()); } for (StringName anim_name : anim_names) { hint_string += "," + anim_name; // Include preceding, as a catch-all. diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp index 55fc52e1db4..b0750ac0ff7 100644 --- a/editor/inspector_dock.cpp +++ b/editor/inspector_dock.cpp @@ -213,7 +213,7 @@ void InspectorDock::_menu_option_confirm(int p_option, bool p_confirmed) { current->get_method_list(&methods); ERR_FAIL_INDEX(idx, methods.size()); - String name = methods[idx].name; + String name = methods.get(idx).name; current->call(name); } @@ -232,8 +232,8 @@ void InspectorDock::_load_resource(const String &p_type) { ResourceLoader::get_recognized_extensions_for_type(p_type, &extensions); load_resource_dialog->clear_filters(); - for (int i = 0; i < extensions.size(); i++) { - load_resource_dialog->add_filter("*." + extensions[i], extensions[i].to_upper()); + for (const String &extension : extensions) { + load_resource_dialog->add_filter("*." + extension, extension.to_upper()); } const Vector textfile_ext = ((String)(EDITOR_GET("docks/filesystem/textfile_extensions"))).split(",", false); diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 3399f265fc6..8de00dfcd11 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -1025,8 +1025,7 @@ void AnimationPlayerEditor::_update_name_dialog_library_dropdown() { } int current_lib_id = index_offset; // Don't default to [Global] if it doesn't exist yet. - for (int i = 0; i < libraries.size(); i++) { - StringName library_name = libraries[i]; + for (const StringName &library_name : libraries) { if (!EditorNode::get_singleton()->is_resource_read_only(player->get_animation_library(library_name))) { library->add_item((library_name == StringName()) ? String(TTR("[Global]")) : String(library_name)); library->set_item_metadata(valid_library_count, String(library_name)); @@ -1043,8 +1042,7 @@ void AnimationPlayerEditor::_update_name_dialog_library_dropdown() { // one which isn't a read-only library. bool auto_assigning_non_global_library = false; if (current_library_name == StringName() && valid_library_count > 0) { - for (int i = 0; i < libraries.size(); i++) { - StringName library_name = libraries[i]; + for (const StringName &library_name : libraries) { if (!EditorNode::get_singleton()->is_resource_read_only(player->get_animation_library(library_name))) { current_library_name = library_name; current_lib_id = 0; diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 79a4269f01d..e2ef7c08ace 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -453,8 +453,8 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, unsig Point2 offset = grid_offset; if (snap_relative) { List selection = _get_edited_canvas_items(); - if (selection.size() == 1 && Object::cast_to(selection[0])) { - offset = Object::cast_to(selection[0])->get_global_position(); + if (selection.size() == 1 && Object::cast_to(selection.front()->get())) { + offset = Object::cast_to(selection.front()->get())->get_global_position(); } else if (selection.size() > 0) { offset = _get_encompassing_rect_from_list(selection).position; } @@ -756,7 +756,7 @@ bool CanvasItemEditor::_select_click_on_item(CanvasItem *item, Point2 p_click_po still_selected = false; if (editor_selection->get_selected_node_list().size() == 1) { - EditorNode::get_singleton()->push_item(editor_selection->get_selected_node_list()[0]); + EditorNode::get_singleton()->push_item(editor_selection->get_selected_node_list().front()->get()); } } else { // Add the item to the selection @@ -1373,7 +1373,7 @@ bool CanvasItemEditor::_gui_input_pivot(const Ref &p_event) { drag_from = transform.affine_inverse().xform(event_pos); Vector2 new_pos; if (drag_selection.size() == 1) { - new_pos = snap_point(drag_from, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, drag_selection[0]); + new_pos = snap_point(drag_from, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, drag_selection.front()->get()); } else { new_pos = snap_point(drag_from, SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, nullptr, drag_selection); } @@ -1394,7 +1394,7 @@ bool CanvasItemEditor::_gui_input_pivot(const Ref &p_event) { _restore_canvas_item_state(drag_selection); Vector2 new_pos; if (drag_selection.size() == 1) { - new_pos = snap_point(drag_to, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, drag_selection[0]); + new_pos = snap_point(drag_to, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, drag_selection.front()->get()); } else { new_pos = snap_point(drag_to, SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL); } @@ -1412,9 +1412,9 @@ bool CanvasItemEditor::_gui_input_pivot(const Ref &p_event) { drag_selection, vformat( TTR("Set CanvasItem \"%s\" Pivot Offset to (%d, %d)"), - drag_selection[0]->get_name(), - drag_selection[0]->_edit_get_pivot().x, - drag_selection[0]->_edit_get_pivot().y)); + drag_selection.front()->get()->get_name(), + drag_selection.front()->get()->_edit_get_pivot().x, + drag_selection.front()->get()->_edit_get_pivot().y)); _reset_drag(); return true; } @@ -1465,7 +1465,7 @@ bool CanvasItemEditor::_gui_input_rotate(const Ref &p_event) { if (drag_selection.size() > 0) { drag_type = DRAG_ROTATE; drag_from = transform.affine_inverse().xform(b->get_position()); - CanvasItem *ci = drag_selection[0]; + CanvasItem *ci = drag_selection.front()->get(); if (!Math::is_inf(temp_pivot.x) || !Math::is_inf(temp_pivot.y)) { drag_rotation_center = temp_pivot; } else if (ci->_edit_use_pivot()) { @@ -1514,8 +1514,8 @@ bool CanvasItemEditor::_gui_input_rotate(const Ref &p_event) { _commit_canvas_item_state( drag_selection, vformat(TTR("Rotate CanvasItem \"%s\" to %d degrees"), - drag_selection[0]->get_name(), - Math::rad_to_deg(drag_selection[0]->_edit_get_rotation())), + drag_selection.front()->get()->get_name(), + Math::rad_to_deg(drag_selection.front()->get()->_edit_get_rotation())), true); } @@ -1545,7 +1545,7 @@ bool CanvasItemEditor::_gui_input_open_scene_on_double_click(const Refget_button_index() == MouseButton::LEFT && b->is_pressed() && b->is_double_click() && tool == TOOL_SELECT) { List selection = _get_edited_canvas_items(); if (selection.size() == 1) { - CanvasItem *ci = selection[0]; + CanvasItem *ci = selection.front()->get(); if (!ci->get_scene_file_path().is_empty() && ci != EditorNode::get_singleton()->get_edited_scene()) { EditorNode::get_singleton()->open_request(ci->get_scene_file_path()); return true; @@ -1564,7 +1564,7 @@ bool CanvasItemEditor::_gui_input_anchors(const Ref &p_event) { if (b.is_valid() && b->get_button_index() == MouseButton::LEFT && b->is_pressed() && tool == TOOL_SELECT) { List selection = _get_edited_canvas_items(); if (selection.size() == 1) { - Control *control = Object::cast_to(selection[0]); + Control *control = Object::cast_to(selection.front()->get()); if (control && _is_node_movable(control)) { Vector2 anchor_pos[4]; anchor_pos[0] = Vector2(control->get_anchor(SIDE_LEFT), control->get_anchor(SIDE_TOP)); @@ -1613,7 +1613,7 @@ bool CanvasItemEditor::_gui_input_anchors(const Ref &p_event) { // Drag the anchor if (m.is_valid()) { _restore_canvas_item_state(drag_selection); - Control *control = Object::cast_to(drag_selection[0]); + Control *control = Object::cast_to(drag_selection.front()->get()); drag_to = transform.affine_inverse().xform(m->get_position()); @@ -1684,7 +1684,7 @@ bool CanvasItemEditor::_gui_input_anchors(const Ref &p_event) { if (drag_selection.size() >= 1 && b.is_valid() && b->get_button_index() == MouseButton::LEFT && !b->is_pressed()) { _commit_canvas_item_state( drag_selection, - vformat(TTR("Move CanvasItem \"%s\" Anchor"), drag_selection[0]->get_name())); + vformat(TTR("Move CanvasItem \"%s\" Anchor"), drag_selection.front()->get()->get_name())); _reset_drag(); return true; } @@ -1709,7 +1709,7 @@ bool CanvasItemEditor::_gui_input_resize(const Ref &p_event) { if (b.is_valid() && b->get_button_index() == MouseButton::LEFT && b->is_pressed() && tool == TOOL_SELECT) { List selection = _get_edited_canvas_items(); if (selection.size() == 1) { - CanvasItem *ci = selection[0]; + CanvasItem *ci = selection.front()->get(); if (ci->_edit_use_rect() && _is_node_movable(ci)) { Rect2 rect = ci->_edit_get_rect(); Transform2D xform = transform * ci->get_global_transform_with_canvas(); @@ -1770,7 +1770,7 @@ bool CanvasItemEditor::_gui_input_resize(const Ref &p_event) { drag_type == DRAG_TOP_LEFT || drag_type == DRAG_TOP_RIGHT || drag_type == DRAG_BOTTOM_LEFT || drag_type == DRAG_BOTTOM_RIGHT) { // Resize the node if (m.is_valid()) { - CanvasItem *ci = drag_selection[0]; + CanvasItem *ci = drag_selection.front()->get(); CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data(ci); //Reset state ci->_edit_set_state(se->undo_state); @@ -1855,7 +1855,7 @@ bool CanvasItemEditor::_gui_input_resize(const Ref &p_event) { // Confirm resize if (drag_selection.size() >= 1 && b.is_valid() && b->get_button_index() == MouseButton::LEFT && !b->is_pressed()) { - const Node2D *node2d = Object::cast_to(drag_selection[0]); + const Node2D *node2d = Object::cast_to(drag_selection.front()->get()); if (node2d) { // Extends from Node2D. // Node2D doesn't have an actual stored rect size, unlike Controls. @@ -1863,9 +1863,9 @@ bool CanvasItemEditor::_gui_input_resize(const Ref &p_event) { drag_selection, vformat( TTR("Scale Node2D \"%s\" to (%s, %s)"), - drag_selection[0]->get_name(), - Math::snapped(drag_selection[0]->_edit_get_scale().x, 0.01), - Math::snapped(drag_selection[0]->_edit_get_scale().y, 0.01)), + drag_selection.front()->get()->get_name(), + Math::snapped(drag_selection.front()->get()->_edit_get_scale().x, 0.01), + Math::snapped(drag_selection.front()->get()->_edit_get_scale().y, 0.01)), true); } else { // Extends from Control. @@ -1873,9 +1873,9 @@ bool CanvasItemEditor::_gui_input_resize(const Ref &p_event) { drag_selection, vformat( TTR("Resize Control \"%s\" to (%d, %d)"), - drag_selection[0]->get_name(), - drag_selection[0]->_edit_get_rect().size.x, - drag_selection[0]->_edit_get_rect().size.y), + drag_selection.front()->get()->get_name(), + drag_selection.front()->get()->_edit_get_rect().size.x, + drag_selection.front()->get()->_edit_get_rect().size.y), true); } @@ -1912,7 +1912,7 @@ bool CanvasItemEditor::_gui_input_scale(const Ref &p_event) { if (b.is_valid() && b->get_button_index() == MouseButton::LEFT && b->is_pressed() && ((b->is_alt_pressed() && b->is_command_or_control_pressed()) || tool == TOOL_SCALE)) { List selection = _get_edited_canvas_items(); if (selection.size() == 1) { - CanvasItem *ci = selection[0]; + CanvasItem *ci = selection.front()->get(); if (_is_node_movable(ci)) { Transform2D xform = transform * ci->get_global_transform_with_canvas(); @@ -1947,7 +1947,7 @@ bool CanvasItemEditor::_gui_input_scale(const Ref &p_event) { // Resize the node if (m.is_valid()) { _restore_canvas_item_state(drag_selection); - CanvasItem *ci = drag_selection[0]; + CanvasItem *ci = drag_selection.front()->get(); drag_to = transform.affine_inverse().xform(m->get_position()); @@ -2015,9 +2015,9 @@ bool CanvasItemEditor::_gui_input_scale(const Ref &p_event) { _commit_canvas_item_state( drag_selection, vformat(TTR("Scale CanvasItem \"%s\" to (%s, %s)"), - drag_selection[0]->get_name(), - Math::snapped(drag_selection[0]->_edit_get_scale().x, 0.01), - Math::snapped(drag_selection[0]->_edit_get_scale().y, 0.01)), + drag_selection.front()->get()->get_name(), + Math::snapped(drag_selection.front()->get()->_edit_get_scale().x, 0.01), + Math::snapped(drag_selection.front()->get()->_edit_get_scale().y, 0.01)), true); } if (key_auto_insert_button->is_pressed()) { @@ -2053,15 +2053,15 @@ bool CanvasItemEditor::_gui_input_move(const Ref &p_event) { if (selection.size() > 0) { drag_selection.clear(); - for (int i = 0; i < selection.size(); i++) { - if (_is_node_movable(selection[i], true)) { - drag_selection.push_back(selection[i]); + for (CanvasItem *E : selection) { + if (_is_node_movable(E, true)) { + drag_selection.push_back(E); } } drag_type = DRAG_MOVE; - CanvasItem *ci = selection[0]; + CanvasItem *ci = selection.front()->get(); Transform2D parent_xform = ci->get_global_transform_with_canvas() * ci->get_transform().affine_inverse(); Transform2D unscaled_transform = (transform * parent_xform * ci->_edit_get_transform()).orthonormalized(); Transform2D simple_xform = viewport->get_transform() * unscaled_transform; @@ -2095,8 +2095,8 @@ bool CanvasItemEditor::_gui_input_move(const Ref &p_event) { drag_to = transform.affine_inverse().xform(m->get_position()); Point2 previous_pos; if (drag_selection.size() == 1) { - Transform2D parent_xform = drag_selection[0]->get_global_transform_with_canvas() * drag_selection[0]->get_transform().affine_inverse(); - previous_pos = parent_xform.xform(drag_selection[0]->_edit_get_position()); + Transform2D parent_xform = drag_selection.front()->get()->get_global_transform_with_canvas() * drag_selection.front()->get()->get_transform().affine_inverse(); + previous_pos = parent_xform.xform(drag_selection.front()->get()->_edit_get_position()); } else { previous_pos = _get_encompassing_rect_from_list(drag_selection).position; } @@ -2147,9 +2147,9 @@ bool CanvasItemEditor::_gui_input_move(const Ref &p_event) { drag_selection, vformat( TTR("Move CanvasItem \"%s\" to (%d, %d)"), - drag_selection[0]->get_name(), - drag_selection[0]->_edit_get_position().x, - drag_selection[0]->_edit_get_position().y), + drag_selection.front()->get()->get_name(), + drag_selection.front()->get()->_edit_get_position().x, + drag_selection.front()->get()->_edit_get_position().y), true); } } @@ -2225,15 +2225,15 @@ bool CanvasItemEditor::_gui_input_move(const Ref &p_event) { Point2 previous_pos; if (drag_selection.size() == 1) { - Transform2D xform = drag_selection[0]->get_global_transform_with_canvas() * drag_selection[0]->get_transform().affine_inverse(); - previous_pos = xform.xform(drag_selection[0]->_edit_get_position()); + Transform2D xform = drag_selection.front()->get()->get_global_transform_with_canvas() * drag_selection.front()->get()->get_transform().affine_inverse(); + previous_pos = xform.xform(drag_selection.front()->get()->_edit_get_position()); } else { previous_pos = _get_encompassing_rect_from_list(drag_selection).position; } Point2 new_pos; if (drag_selection.size() == 1) { - Node2D *node_2d = Object::cast_to(drag_selection[0]); + Node2D *node_2d = Object::cast_to(drag_selection.front()->get()); if (node_2d && move_local_base_rotated) { Transform2D m2; m2.rotate(node_2d->get_rotation()); @@ -2271,9 +2271,9 @@ bool CanvasItemEditor::_gui_input_move(const Ref &p_event) { _commit_canvas_item_state( drag_selection, vformat(TTR("Move CanvasItem \"%s\" to (%d, %d)"), - drag_selection[0]->get_name(), - drag_selection[0]->_edit_get_position().x, - drag_selection[0]->_edit_get_position().y), + drag_selection.front()->get()->get_name(), + drag_selection.front()->get()->_edit_get_position().x, + drag_selection.front()->get()->_edit_get_position().y), true); } _reset_drag(); @@ -2440,9 +2440,9 @@ bool CanvasItemEditor::_gui_input_select(const Ref &p_event) { List selection2 = _get_edited_canvas_items(); drag_selection.clear(); - for (int i = 0; i < selection2.size(); i++) { - if (_is_node_movable(selection2[i], true)) { - drag_selection.push_back(selection2[i]); + for (CanvasItem *E : selection2) { + if (_is_node_movable(E, true)) { + drag_selection.push_back(E); } } @@ -2474,7 +2474,7 @@ bool CanvasItemEditor::_gui_input_select(const Ref &p_event) { _find_canvas_items_in_rect(Rect2(bsfrom, bsto - bsfrom), scene, &selitems); if (selitems.size() == 1 && editor_selection->get_selected_node_list().is_empty()) { - EditorNode::get_singleton()->push_item(selitems[0]); + EditorNode::get_singleton()->push_item(selitems.front()->get()); } for (CanvasItem *E : selitems) { editor_selection->add_node(E); @@ -2722,7 +2722,7 @@ Control::CursorShape CanvasItemEditor::get_cursor_shape(const Point2 &p_pos) con List selection = _get_edited_canvas_items(); if (selection.size() == 1) { - const double angle = Math::fposmod((double)selection[0]->get_global_transform_with_canvas().get_rotation(), Math_PI); + const double angle = Math::fposmod((double)selection.front()->get()->get_global_transform_with_canvas().get_rotation(), Math_PI); if (angle > Math_PI * 7.0 / 8.0) { rotation_array_index = 0; } else if (angle > Math_PI * 5.0 / 8.0) { @@ -6057,8 +6057,8 @@ void CanvasItemEditorViewport::_show_resource_type_selector() { List btn_list; button_group->get_buttons(&btn_list); - for (int i = 0; i < btn_list.size(); i++) { - CheckBox *check = Object::cast_to(btn_list[i]); + for (BaseButton *btn : btn_list) { + CheckBox *check = Object::cast_to(btn); check->set_pressed(check->get_text() == default_texture_node_type); } selector->set_title(vformat(TTR("Add %s"), default_texture_node_type)); @@ -6091,7 +6091,7 @@ void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p List selected_nodes = EditorNode::get_singleton()->get_editor_selection()->get_selected_node_list(); Node *root_node = EditorNode::get_singleton()->get_edited_scene(); if (selected_nodes.size() > 0) { - Node *selected_node = selected_nodes[0]; + Node *selected_node = selected_nodes.front()->get(); target_node = selected_node; if (is_alt) { target_node = root_node; @@ -6119,8 +6119,8 @@ void CanvasItemEditorViewport::_update_theme() { List btn_list; button_group->get_buttons(&btn_list); - for (int i = 0; i < btn_list.size(); i++) { - CheckBox *check = Object::cast_to(btn_list[i]); + for (BaseButton *btn : btn_list) { + CheckBox *check = Object::cast_to(btn); check->set_icon(get_editor_theme_icon(check->get_text())); } diff --git a/editor/plugins/editor_debugger_plugin.cpp b/editor/plugins/editor_debugger_plugin.cpp index af9ff5056a0..1adbce79419 100644 --- a/editor/plugins/editor_debugger_plugin.cpp +++ b/editor/plugins/editor_debugger_plugin.cpp @@ -140,8 +140,8 @@ EditorDebuggerPlugin::~EditorDebuggerPlugin() { } void EditorDebuggerPlugin::clear() { - for (int i = 0; i < sessions.size(); i++) { - sessions[i]->detach_debugger(); + for (Ref &session : sessions) { + session->detach_debugger(); } sessions.clear(); } @@ -157,13 +157,13 @@ void EditorDebuggerPlugin::setup_session(int p_idx) { Ref EditorDebuggerPlugin::get_session(int p_idx) { ERR_FAIL_INDEX_V(p_idx, sessions.size(), nullptr); - return sessions[p_idx]; + return sessions.get(p_idx); } Array EditorDebuggerPlugin::get_sessions() { Array ret; - for (int i = 0; i < sessions.size(); i++) { - ret.push_back(sessions[i]); + for (const Ref &session : sessions) { + ret.push_back(session); } return ret; } diff --git a/editor/plugins/gizmos/joint_3d_gizmo_plugin.cpp b/editor/plugins/gizmos/joint_3d_gizmo_plugin.cpp index c15ddef933f..ae24b4250e1 100644 --- a/editor/plugins/gizmos/joint_3d_gizmo_plugin.cpp +++ b/editor/plugins/gizmos/joint_3d_gizmo_plugin.cpp @@ -295,7 +295,7 @@ void Joint3DGizmoPlugin::incremental_update_gizmos() { if (!current_gizmos.is_empty()) { update_idx++; update_idx = update_idx % current_gizmos.size(); - redraw(current_gizmos[update_idx]); + redraw(current_gizmos.get(update_idx)); } } diff --git a/editor/plugins/mesh_library_editor_plugin.cpp b/editor/plugins/mesh_library_editor_plugin.cpp index 8bfd3d0957d..1a5727a1e80 100644 --- a/editor/plugins/mesh_library_editor_plugin.cpp +++ b/editor/plugins/mesh_library_editor_plugin.cpp @@ -253,8 +253,8 @@ MeshLibraryEditor::MeshLibraryEditor() { ResourceLoader::get_recognized_extensions_for_type("PackedScene", &extensions); file->clear_filters(); file->set_title(TTR("Import Scene")); - for (int i = 0; i < extensions.size(); i++) { - file->add_filter("*." + extensions[i], extensions[i].to_upper()); + for (const String &extension : extensions) { + file->add_filter("*." + extension, extension.to_upper()); } add_child(file); file->connect("file_selected", callable_mp(this, &MeshLibraryEditor::_import_scene_cbk)); diff --git a/editor/plugins/node_3d_editor_gizmos.cpp b/editor/plugins/node_3d_editor_gizmos.cpp index 7e98950f321..3f86d30368a 100644 --- a/editor/plugins/node_3d_editor_gizmos.cpp +++ b/editor/plugins/node_3d_editor_gizmos.cpp @@ -1162,8 +1162,8 @@ void EditorNode3DGizmoPlugin::commit_subgizmos(const EditorNode3DGizmo *p_gizmo, void EditorNode3DGizmoPlugin::set_state(int p_state) { current_state = p_state; - for (int i = 0; i < current_gizmos.size(); ++i) { - current_gizmos[i]->set_hidden(current_state == HIDDEN); + for (EditorNode3DGizmo *current : current_gizmos) { + current->set_hidden(current_state == HIDDEN); } } @@ -1180,9 +1180,9 @@ EditorNode3DGizmoPlugin::EditorNode3DGizmoPlugin() { } EditorNode3DGizmoPlugin::~EditorNode3DGizmoPlugin() { - for (int i = 0; i < current_gizmos.size(); ++i) { - current_gizmos[i]->set_plugin(nullptr); - current_gizmos[i]->get_node_3d()->remove_gizmo(current_gizmos[i]); + for (EditorNode3DGizmo *current : current_gizmos) { + current->set_plugin(nullptr); + current->get_node_3d()->remove_gizmo(current); } if (Node3DEditor::get_singleton()) { Node3DEditor::get_singleton()->update_all_gizmos(); diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 4a418e62ca6..af38f51a25f 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -764,7 +764,7 @@ void Node3DEditorViewport::_select_clicked(bool p_allow_locked) { } if (editor_selection->get_selected_node_list().size() == 1) { - EditorNode::get_singleton()->edit_node(editor_selection->get_selected_node_list()[0]); + EditorNode::get_singleton()->edit_node(editor_selection->get_selected_node_list().front()->get()); } } } @@ -1084,7 +1084,7 @@ void Node3DEditorViewport::_select_region() { } if (editor_selection->get_selected_node_list().size() == 1) { - EditorNode::get_singleton()->edit_node(editor_selection->get_selected_node_list()[0]); + EditorNode::get_singleton()->edit_node(editor_selection->get_selected_node_list().front()->get()); } } @@ -4592,7 +4592,7 @@ void Node3DEditorViewport::drop_data_fw(const Point2 &p_point, const Variant &p_ List selected_nodes = EditorNode::get_singleton()->get_editor_selection()->get_selected_node_list(); Node *root_node = EditorNode::get_singleton()->get_edited_scene(); if (selected_nodes.size() > 0) { - Node *selected_node = selected_nodes[0]; + Node *selected_node = selected_nodes.front()->get(); target_node = selected_node; if (is_alt) { target_node = root_node; @@ -6069,9 +6069,9 @@ void Node3DEditor::set_state(const Dictionary &p_state) { continue; } int state = EditorNode3DGizmoPlugin::VISIBLE; - for (int i = 0; i < keys.size(); i++) { - if (gizmo_plugins_by_name.write[j]->get_gizmo_name() == String(keys[i])) { - state = gizmos_status[keys[i]]; + for (const Variant &key : keys) { + if (gizmo_plugins_by_name.write[j]->get_gizmo_name() == String(key)) { + state = gizmos_status[key]; break; } } diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp index 2e0a9c72728..c95195ae2a0 100644 --- a/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/editor/plugins/resource_preloader_editor_plugin.cpp @@ -90,8 +90,8 @@ void ResourcePreloaderEditor::_load_pressed() { file->clear_filters(); List extensions; ResourceLoader::get_recognized_extensions_for_type("", &extensions); - for (int i = 0; i < extensions.size(); i++) { - file->add_filter("*." + extensions[i]); + for (const String &extension : extensions) { + file->add_filter("*." + extension); } file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILES); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index c48af906229..e901f38944b 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -1275,8 +1275,8 @@ void ScriptEditor::_menu_option(int p_option) { List extensions; ResourceLoader::get_recognized_extensions_for_type("Script", &extensions); file_dialog->clear_filters(); - for (int i = 0; i < extensions.size(); i++) { - file_dialog->add_filter("*." + extensions[i], extensions[i].to_upper()); + for (const String &extension : extensions) { + file_dialog->add_filter("*." + extension, extension.to_upper()); } for (const String &E : textfile_extensions) { diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 561edcf8bf1..09073262d71 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -531,9 +531,9 @@ void ScriptTextEditor::_validate_script() { if (errors.size() > 0) { // TRANSLATORS: Script error pointing to a line and column number. - String error_text = vformat(TTR("Error at (%d, %d):"), errors[0].line, errors[0].column) + " " + errors[0].message; + String error_text = vformat(TTR("Error at (%d, %d):"), errors.front()->get().line, errors.front()->get().column) + " " + errors.front()->get().message; code_editor->set_error(error_text); - code_editor->set_error_pos(errors[0].line - 1, errors[0].column - 1); + code_editor->set_error_pos(errors.front()->get().line - 1, errors.front()->get().column - 1); } script_is_valid = false; } else { @@ -1217,8 +1217,8 @@ void ScriptTextEditor::_update_connected_methods() { while (base_class) { List methods; ClassDB::get_method_list(base_class, &methods, true); - for (int j = 0; j < methods.size(); j++) { - if (methods[j].name == name) { + for (const MethodInfo &mi : methods) { + if (mi.name == name) { found_base_class = "builtin:" + base_class; break; } diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index 5e67cbc6ce8..a28952d8e77 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -60,8 +60,8 @@ void SpriteFramesEditor::_open_sprite_sheet() { file_split_sheet->clear_filters(); List extensions; ResourceLoader::get_recognized_extensions_for_type("Texture2D", &extensions); - for (int i = 0; i < extensions.size(); i++) { - file_split_sheet->add_filter("*." + extensions[i]); + for (const String &extension : extensions) { + file_split_sheet->add_filter("*." + extension); } file_split_sheet->popup_file_dialog(); @@ -668,8 +668,8 @@ void SpriteFramesEditor::_load_pressed() { file->clear_filters(); List extensions; ResourceLoader::get_recognized_extensions_for_type("Texture2D", &extensions); - for (int i = 0; i < extensions.size(); i++) { - file->add_filter("*." + extensions[i]); + for (const String &extension : extensions) { + file->add_filter("*." + extension); } file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILES); @@ -1117,10 +1117,10 @@ void SpriteFramesEditor::_animation_remove_confirmed() { frames->get_animation_list(&anim_names); anim_names.sort_custom(); if (anim_names.size() >= 2) { - if (edited_anim == anim_names[0]) { - new_edited = anim_names[1]; + if (edited_anim == anim_names.get(0)) { + new_edited = anim_names.get(1); } else { - new_edited = anim_names[0]; + new_edited = anim_names.get(0); } } else { new_edited = StringName(); @@ -1648,7 +1648,7 @@ void SpriteFramesEditor::_fetch_sprite_node() { Node *selected = nullptr; EditorSelection *editor_selection = EditorNode::get_singleton()->get_editor_selection(); if (editor_selection->get_selected_node_list().size() == 1) { - selected = editor_selection->get_selected_node_list()[0]; + selected = editor_selection->get_selected_node_list().front()->get(); } bool show_node_edit = false; diff --git a/editor/plugins/text_shader_editor.cpp b/editor/plugins/text_shader_editor.cpp index a1d1df0f837..42719e992e2 100644 --- a/editor/plugins/text_shader_editor.cpp +++ b/editor/plugins/text_shader_editor.cpp @@ -583,9 +583,7 @@ void ShaderTextEditor::_update_warning_panel() { int warning_count = 0; warnings_panel->push_table(2); - for (int i = 0; i < warnings.size(); i++) { - ShaderWarning &w = warnings[i]; - + for (const ShaderWarning &w : warnings) { if (warning_count == 0) { if (saved_treat_warning_as_errors) { String error_text = "error(" + itos(w.get_line()) + "): " + w.get_message() + " " + TTR("Warnings should be fixed to prevent errors."); diff --git a/editor/plugins/version_control_editor_plugin.cpp b/editor/plugins/version_control_editor_plugin.cpp index 91738384717..59e5a595832 100644 --- a/editor/plugins/version_control_editor_plugin.cpp +++ b/editor/plugins/version_control_editor_plugin.cpp @@ -75,8 +75,8 @@ void VersionControlEditorPlugin::_notification(int p_what) { void VersionControlEditorPlugin::_populate_available_vcs_names() { set_up_choice->clear(); - for (int i = 0; i < available_plugins.size(); i++) { - set_up_choice->add_item(available_plugins[i]); + for (const StringName &available_plugin : available_plugins) { + set_up_choice->add_item(available_plugin); } } @@ -193,10 +193,11 @@ void VersionControlEditorPlugin::_refresh_branch_list() { String current_branch = EditorVCSInterface::get_singleton()->get_current_branch_name(); - for (int i = 0; i < branch_list.size(); i++) { - branch_select->add_icon_item(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("VcsBranches"), EditorStringName(EditorIcons)), branch_list[i], i); + int i = 0; + for (List::ConstIterator itr = branch_list.begin(); itr != branch_list.end(); ++itr, ++i) { + branch_select->add_icon_item(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("VcsBranches"), EditorStringName(EditorIcons)), *itr, i); - if (branch_list[i] == current_branch) { + if (*itr == current_branch) { branch_select->select(i); } } @@ -253,11 +254,12 @@ void VersionControlEditorPlugin::_refresh_remote_list() { remote_select->set_disabled(remotes.is_empty()); - for (int i = 0; i < remotes.size(); i++) { - remote_select->add_icon_item(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("ArrowUp"), EditorStringName(EditorIcons)), remotes[i], i); - remote_select->set_item_metadata(i, remotes[i]); + int i = 0; + for (List::ConstIterator itr = remotes.begin(); itr != remotes.end(); ++itr, ++i) { + remote_select->add_icon_item(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("ArrowUp"), EditorStringName(EditorIcons)), *itr, i); + remote_select->set_item_metadata(i, *itr); - if (remotes[i] == current_remote) { + if (*itr == current_remote) { remote_select->select(i); } } @@ -589,9 +591,7 @@ void VersionControlEditorPlugin::_display_diff(int p_idx) { diff->pop(); } - for (int i = 0; i < diff_content.size(); i++) { - EditorVCSInterface::DiffFile diff_file = diff_content[i]; - + for (const EditorVCSInterface::DiffFile &diff_file : diff_content) { diff->push_font(EditorNode::get_singleton()->get_editor_theme()->get_font(SNAME("doc_bold"), EditorStringName(EditorFonts))); diff->push_color(EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("accent_color"), EditorStringName(Editor))); diff->add_text(TTR("File:") + " " + diff_file.new_file); @@ -599,9 +599,7 @@ void VersionControlEditorPlugin::_display_diff(int p_idx) { diff->pop(); diff->push_font(EditorNode::get_singleton()->get_editor_theme()->get_font(SNAME("status_source"), EditorStringName(EditorFonts))); - for (int j = 0; j < diff_file.diff_hunks.size(); j++) { - EditorVCSInterface::DiffHunk hunk = diff_file.diff_hunks[j]; - + for (EditorVCSInterface::DiffHunk hunk : diff_file.diff_hunks) { String old_start = String::num_int64(hunk.old_start); String new_start = String::num_int64(hunk.new_start); String old_lines = String::num_int64(hunk.old_lines); @@ -628,10 +626,9 @@ void VersionControlEditorPlugin::_display_diff(int p_idx) { } void VersionControlEditorPlugin::_display_diff_split_view(List &p_diff_content) { - List parsed_diff; + LocalVector parsed_diff; - for (int i = 0; i < p_diff_content.size(); i++) { - EditorVCSInterface::DiffLine diff_line = p_diff_content[i]; + for (EditorVCSInterface::DiffLine diff_line : p_diff_content) { String line = diff_line.content.strip_edges(false, true); if (diff_line.new_line_no >= 0 && diff_line.old_line_no >= 0) { @@ -643,12 +640,12 @@ void VersionControlEditorPlugin::_display_diff_split_view(List= 0 && parsed_diff[j].new_line_no == -1) { j--; } - if (j == parsed_diff.size() - 1) { + if (j == (int32_t)parsed_diff.size() - 1) { // no lines are modified diff_line.new_text = line; diff_line.old_text = ""; @@ -677,7 +674,7 @@ void VersionControlEditorPlugin::_display_diff_split_view(Listset_table_column_expand(2, true); diff->set_table_column_expand(5, true); - for (int i = 0; i < parsed_diff.size(); i++) { + for (uint32_t i = 0; i < parsed_diff.size(); i++) { EditorVCSInterface::DiffLine diff_line = parsed_diff[i]; bool has_change = diff_line.status != " "; @@ -757,8 +754,7 @@ void VersionControlEditorPlugin::_display_diff_unified_view(Listdp_props.size(); i++) { - const VisualShaderNodeCustom::DropDownListProperty &dp = custom_node->dp_props[i]; + int i = 0; + for (List::ConstIterator itr = custom_node->dp_props.begin(); itr != custom_node->dp_props.end(); ++itr, ++i) { + const VisualShaderNodeCustom::DropDownListProperty &dp = *itr; if (first) { first = false; @@ -1828,9 +1829,9 @@ void VisualShaderEditor::_update_nodes() { List class_list; ScriptServer::get_global_class_list(&class_list); - for (int i = 0; i < class_list.size(); i++) { - if (ScriptServer::get_global_class_native_base(class_list[i]) == "VisualShaderNodeCustom") { - String script_path = ScriptServer::get_global_class_path(class_list[i]); + for (const StringName &E : class_list) { + if (ScriptServer::get_global_class_native_base(E) == "VisualShaderNodeCustom") { + String script_path = ScriptServer::get_global_class_path(E); Ref res = ResourceLoader::load(script_path); ERR_CONTINUE(res.is_null()); ERR_CONTINUE(!res->is_class("Script")); @@ -1858,16 +1859,16 @@ void VisualShaderEditor::_update_nodes() { List class_list; ClassDB::get_class_list(&class_list); - for (int i = 0; i < class_list.size(); i++) { - if (ClassDB::get_parent_class(class_list[i]) == "VisualShaderNodeCustom") { - Object *instance = ClassDB::instantiate(class_list[i]); + for (const StringName &E : class_list) { + if (ClassDB::get_parent_class(E) == "VisualShaderNodeCustom") { + Object *instance = ClassDB::instantiate(E); Ref ref = Object::cast_to(instance); ERR_CONTINUE(ref.is_null()); if (!ref->is_available(visual_shader->get_mode(), visual_shader->get_shader_type())) { continue; } Dictionary dict = get_custom_node_data(ref); - dict["type"] = class_list[i]; + dict["type"] = E; dict["script"] = Ref