From d4d658963690289911be4a2b1821210d8471d34a Mon Sep 17 00:00:00 2001 From: Yufeng Ying Date: Tue, 3 Dec 2024 02:00:33 +0800 Subject: [PATCH 1/2] Replace List with LocalVector if used as simple buffer. --- core/io/dir_access.cpp | 6 ++-- core/io/packed_data_container.cpp | 2 +- core/object/class_db.cpp | 10 +++--- core/object/script_language.cpp | 9 +++--- drivers/gles3/storage/material_storage.cpp | 8 ++--- editor/animation_bezier_editor.cpp | 4 +-- editor/animation_track_editor.cpp | 8 ++--- editor/audio_stream_preview.cpp | 7 ++--- editor/debugger/editor_visual_profiler.cpp | 2 +- editor/debugger/script_editor_debugger.cpp | 2 +- editor/doc_tools.cpp | 7 ++--- editor/editor_file_system.cpp | 10 +++--- editor/editor_node.cpp | 8 ++--- editor/editor_settings.cpp | 2 +- editor/gui/editor_file_dialog.cpp | 2 +- editor/gui/scene_tree_editor.cpp | 4 +-- editor/import/resource_importer_texture.cpp | 2 +- .../animation_blend_tree_editor_plugin.cpp | 2 +- .../plugins/asset_library_editor_plugin.cpp | 9 +++--- editor/plugins/canvas_item_editor_plugin.cpp | 6 ++-- .../resource_preloader_editor_plugin.cpp | 2 +- editor/plugins/script_editor_plugin.cpp | 7 ++--- editor/plugins/theme_editor_plugin.cpp | 2 +- .../plugins/visual_shader_editor_plugin.cpp | 10 +++--- editor/scene_tree_dock.cpp | 13 ++++---- modules/gdscript/gdscript.cpp | 4 +-- modules/gdscript/gdscript_function.cpp | 2 +- modules/gdscript/gdscript_parser.cpp | 2 +- modules/mono/class_db_api_json.cpp | 8 ++--- .../scene_replication_interface.cpp | 2 +- modules/webrtc/webrtc_multiplayer_peer.cpp | 4 +-- modules/zip/zip_reader.cpp | 6 ++-- scene/animation/animation_blend_tree.cpp | 2 +- scene/animation/animation_mixer.cpp | 2 +- .../animation_node_state_machine.cpp | 15 +++------ scene/animation/animation_player.cpp | 18 +++++------ scene/gui/code_edit.cpp | 2 +- scene/gui/control.cpp | 2 +- scene/gui/file_dialog.cpp | 2 +- scene/gui/graph_edit.cpp | 2 +- scene/main/node.cpp | 2 +- scene/main/viewport.cpp | 31 ++++++++----------- scene/resources/animation_library.cpp | 2 +- scene/resources/packed_scene.cpp | 7 ++--- scene/resources/visual_shader.cpp | 7 ++--- .../storage_rd/material_storage.cpp | 8 ++--- servers/rendering/shader_compiler.cpp | 2 +- thirdparty/enet/godot.cpp | 2 +- 48 files changed, 127 insertions(+), 151 deletions(-) diff --git a/core/io/dir_access.cpp b/core/io/dir_access.cpp index ca92b3e1181c..7b13aff36a0b 100644 --- a/core/io/dir_access.cpp +++ b/core/io/dir_access.cpp @@ -77,8 +77,8 @@ bool DirAccess::drives_are_shortcuts() { } static Error _erase_recursive(DirAccess *da) { - List dirs; - List files; + LocalVector dirs; + LocalVector files; da->list_dir_begin(); String n = da->get_next(); @@ -484,7 +484,7 @@ class DirChanger { }; Error DirAccess::_copy_dir(Ref &p_target_da, const String &p_to, int p_chmod_flags, bool p_copy_links) { - List dirs; + LocalVector dirs; String curdir = get_current_dir(); list_dir_begin(); diff --git a/core/io/packed_data_container.cpp b/core/io/packed_data_container.cpp index ca236ce05c74..2fb404e56ac5 100644 --- a/core/io/packed_data_container.cpp +++ b/core/io/packed_data_container.cpp @@ -270,7 +270,7 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector &tmpd List keys; d.get_key_list(&keys); - List sortk; + LocalVector sortk; for (const Variant &key : keys) { DictKey dk; diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index 865b6acc4234..c5e66788d9c9 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -381,7 +381,7 @@ uint32_t ClassDB::get_api_hash(APIType p_api) { uint64_t hash = hash_murmur3_one_64(HashMapHasherDefault::hash(VERSION_FULL_CONFIG)); - List class_list; + LocalVector class_list; for (const KeyValue &E : classes) { class_list.push_back(E.key); } @@ -399,7 +399,7 @@ uint32_t ClassDB::get_api_hash(APIType p_api) { { //methods - List snames; + LocalVector snames; for (const KeyValue &F : t->method_map) { String name = F.key.operator String(); @@ -444,7 +444,7 @@ uint32_t ClassDB::get_api_hash(APIType p_api) { { //constants - List snames; + LocalVector snames; for (const KeyValue &F : t->constant_map) { snames.push_back(F.key); @@ -460,7 +460,7 @@ uint32_t ClassDB::get_api_hash(APIType p_api) { { //signals - List snames; + LocalVector snames; for (const KeyValue &F : t->signal_map) { snames.push_back(F.key); @@ -479,7 +479,7 @@ uint32_t ClassDB::get_api_hash(APIType p_api) { { //properties - List snames; + LocalVector snames; for (const KeyValue &F : t->property_setget) { snames.push_back(F.key); diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp index 5afe45ca359f..0f315001ffed 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -483,7 +483,7 @@ StringName ScriptServer::get_global_class_native_base(const String &p_class) { } void ScriptServer::get_global_class_list(List *r_global_classes) { - List classes; + LocalVector classes; for (const KeyValue &E : global_classes) { classes.push_back(E.key); } @@ -764,7 +764,7 @@ void PlaceHolderScriptInstance::update(const List &p_properties, c } properties = p_properties; - List to_remove; + LocalVector to_remove; for (KeyValue &E : values) { if (!new_values.has(E.key)) { @@ -780,9 +780,8 @@ void PlaceHolderScriptInstance::update(const List &p_properties, c } } - while (to_remove.size()) { - values.erase(to_remove.front()->get()); - to_remove.pop_front(); + for (const StringName &E : to_remove) { + values.erase(E); } if (owner && owner->get_script_instance() == this) { diff --git a/drivers/gles3/storage/material_storage.cpp b/drivers/gles3/storage/material_storage.cpp index 04cbf7f2cd14..cbc494be2638 100644 --- a/drivers/gles3/storage/material_storage.cpp +++ b/drivers/gles3/storage/material_storage.cpp @@ -1019,7 +1019,7 @@ void MaterialData::update_textures(const HashMap &p_paramet } { //for textures no longer used, unregister them - List to_delete; + LocalVector to_delete; for (KeyValue &E : used_global_textures) { if (E.value != global_textures_pass) { to_delete.push_back(E.key); @@ -1031,10 +1031,10 @@ void MaterialData::update_textures(const HashMap &p_paramet } } - while (to_delete.front()) { - used_global_textures.erase(to_delete.front()->get()); - to_delete.pop_front(); + for (StringName &name : to_delete) { + used_global_textures.erase(name); } + //handle registering/unregistering global textures if (uses_global_textures != (global_texture_E != nullptr)) { if (uses_global_textures) { diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index 36ca41763873..b3c9d40e7305 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -1745,7 +1745,7 @@ void AnimationBezierTrackEdit::duplicate_selected_keys(real_t p_ofs, bool p_ofs_ EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); undo_redo->create_action(TTR("Animation Duplicate Keys")); - List> new_selection_values; + LocalVector> new_selection_values; for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) { real_t t = animation->track_get_key_time(E->get().first, E->get().second); @@ -1883,7 +1883,7 @@ void AnimationBezierTrackEdit::paste_keys(real_t p_ofs, bool p_ofs_valid) { WARN_PRINT("Pasted animation keys from multiple tracks into single Bezier track"); } - List> new_selection_values; + LocalVector> new_selection_values; for (int i = 0; i < editor->key_clipboard.keys.size(); i++) { const AnimationTrackEditor::KeyClipboard::Key key = editor->key_clipboard.keys[i]; diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index ae2b63deaddf..82353c42e7d8 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -5837,7 +5837,7 @@ void AnimationTrackEditor::_move_selection_commit() { EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); undo_redo->create_action(TTR("Animation Move Keys")); - List<_AnimMoveRestore> to_restore; + LocalVector<_AnimMoveRestore> to_restore; float motion = moving_selection_offset; // 1 - remove the keys. @@ -6146,7 +6146,7 @@ void AnimationTrackEditor::_anim_duplicate_keys(float p_ofs, bool p_ofs_valid, i EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); undo_redo->create_action(TTR("Animation Duplicate Keys")); - List> new_selection_values; + LocalVector> new_selection_values; for (RBMap::Element *E = selection.back(); E; E = E->prev()) { const SelectedKey &sk = E->key(); @@ -6295,7 +6295,7 @@ void AnimationTrackEditor::_anim_paste_keys(float p_ofs, bool p_ofs_valid, int p EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); undo_redo->create_action(TTR("Animation Paste Keys")); - List> new_selection_values; + LocalVector> new_selection_values; for (int i = 0; i < key_clipboard.keys.size(); i++) { const KeyClipboard::Key key = key_clipboard.keys[i]; @@ -6678,7 +6678,7 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) { EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); undo_redo->create_action(TTR("Animation Scale Keys")); - List<_AnimMoveRestore> to_restore; + LocalVector<_AnimMoveRestore> to_restore; // 1 - Remove the keys. for (RBMap::Element *E = selection.back(); E; E = E->prev()) { diff --git a/editor/audio_stream_preview.cpp b/editor/audio_stream_preview.cpp index 8dd4820c4e91..82dead0b56a9 100644 --- a/editor/audio_stream_preview.cpp +++ b/editor/audio_stream_preview.cpp @@ -226,7 +226,7 @@ AudioStreamPreviewGenerator *AudioStreamPreviewGenerator::singleton = nullptr; void AudioStreamPreviewGenerator::_notification(int p_what) { switch (p_what) { case NOTIFICATION_PROCESS: { - List to_erase; + LocalVector to_erase; for (KeyValue &E : previews) { if (!E.value.generating.is_set()) { if (E.value.thread) { @@ -240,9 +240,8 @@ void AudioStreamPreviewGenerator::_notification(int p_what) { } } - while (to_erase.front()) { - previews.erase(to_erase.front()->get()); - to_erase.pop_front(); + for (ObjectID &E : to_erase) { + previews.erase(E); } } break; } diff --git a/editor/debugger/editor_visual_profiler.cpp b/editor/debugger/editor_visual_profiler.cpp index c1de540a0da3..a2ed71ed90a3 100644 --- a/editor/debugger/editor_visual_profiler.cpp +++ b/editor/debugger/editor_visual_profiler.cpp @@ -339,7 +339,7 @@ void EditorVisualProfiler::_update_frame(bool p_focus_selected) { const Metric &m = frame_metrics[cursor_metric]; List stack; - List categories; + LocalVector categories; TreeItem *ensure_selected = nullptr; diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index 56b75b0b2f0b..cb86601c61bb 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -1740,7 +1740,7 @@ void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) { } // Store first else we will be removing as we loop. - List lines; + LocalVector lines; for (TreeItem *breakpoint_item = file_item->get_first_child(); breakpoint_item; breakpoint_item = breakpoint_item->get_next()) { lines.push_back(breakpoint_item->get_meta("line")); } diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp index 842c4acce065..849355fd78d2 100644 --- a/editor/doc_tools.cpp +++ b/editor/doc_tools.cpp @@ -1250,7 +1250,7 @@ Error DocTools::erase_classes(const String &p_dir) { return err; } - List to_erase; + LocalVector to_erase; da->list_dir_begin(); String path; @@ -1263,9 +1263,8 @@ Error DocTools::erase_classes(const String &p_dir) { } da->list_dir_end(); - while (to_erase.size()) { - da->remove(to_erase.front()->get()); - to_erase.pop_front(); + for (String &E : to_erase) { + da->remove(E); } return OK; diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 4911d5c702dc..f85fa1d99495 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -1034,7 +1034,7 @@ void EditorFileSystem::ScanProgress::increment() { } int EditorFileSystem::_scan_new_dir(ScannedDirectory *p_dir, Ref &da) { - List dirs; + LocalVector dirs; List files; String cd = da->get_current_dir(); @@ -1073,15 +1073,15 @@ int EditorFileSystem::_scan_new_dir(ScannedDirectory *p_dir, Ref &da) int nb_files_total_scan = 0; - for (List::Element *E = dirs.front(); E; E = E->next()) { - if (da->change_dir(E->get()) == OK) { + for (String &dir : dirs) { + if (da->change_dir(dir) == OK) { String d = da->get_current_dir(); if (d == cd || !d.begins_with(cd)) { da->change_dir(cd); //avoid recursion } else { ScannedDirectory *sd = memnew(ScannedDirectory); - sd->name = E->get(); + sd->name = dir; sd->full_path = p_dir->full_path.path_join(sd->name); nb_files_total_scan += _scan_new_dir(sd, da); @@ -1091,7 +1091,7 @@ int EditorFileSystem::_scan_new_dir(ScannedDirectory *p_dir, Ref &da) da->change_dir(".."); } } else { - ERR_PRINT("Cannot go into subdir '" + E->get() + "'."); + ERR_PRINT("Cannot go into subdir '" + dir + "'."); } } diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 5030589f5d87..cd2dc37bb567 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -921,7 +921,7 @@ void EditorNode::_plugin_over_self_own(EditorPlugin *p_plugin) { } void EditorNode::_resources_changed(const Vector &p_resources) { - List> changed; + LocalVector> changed; int rc = p_resources.size(); for (int i = 0; i < rc; i++) { @@ -2301,7 +2301,7 @@ void EditorNode::edit_item(Object *p_object, Object *p_editing_owner) { // Remove editor plugins no longer used by this editing owner. Keep the ones that can // still be reused by the new edited object. - List to_remove; + LocalVector to_remove; for (EditorPlugin *plugin : active_plugins[owner_id]) { if (!available_plugins.has(plugin)) { to_remove.push_back(plugin); @@ -2414,7 +2414,7 @@ void EditorNode::hide_unused_editors(const Object *p_editing_owner) { } else { // If no editing owner is provided, this method will go over all owners and check if they are valid. // This is to sweep properties that were removed from the inspector. - List to_remove; + LocalVector to_remove; for (KeyValue> &kv : active_plugins) { Object *context = ObjectDB::get_instance(kv.key); if (context) { @@ -6230,7 +6230,7 @@ void EditorNode::reload_instances_with_path_in_edited_scenes() { } // Store all the paths for any selected nodes which are ancestors of the node we're replacing. - List selected_node_paths; + LocalVector selected_node_paths; for (Node *selected_node : editor_selection->get_selected_node_list()) { if (selected_node == original_node || original_node->is_ancestor_of(selected_node)) { selected_node_paths.push_back(original_node->get_path_to(selected_node)); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 7322e2aefb61..c40df272efc9 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -1601,7 +1601,7 @@ void EditorSettings::list_text_editor_themes() { Ref d = DirAccess::open(EditorPaths::get_singleton()->get_text_editor_themes_dir()); if (d.is_valid()) { - List custom_themes; + LocalVector custom_themes; d->list_dir_begin(); String file = d->get_next(); while (!file.is_empty()) { diff --git a/editor/gui/editor_file_dialog.cpp b/editor/gui/editor_file_dialog.cpp index 21967f3e0880..91f8c22bd9ec 100644 --- a/editor/gui/editor_file_dialog.cpp +++ b/editor/gui/editor_file_dialog.cpp @@ -1053,7 +1053,7 @@ void EditorFileDialog::update_file_list() { } sort_file_info_list(file_infos, file_sort); - List patterns; + LocalVector patterns; // build filter if (filter->get_selected() == filter->get_item_count() - 1) { // match all diff --git a/editor/gui/scene_tree_editor.cpp b/editor/gui/scene_tree_editor.cpp index 2d51716c88d3..f8dedf840008 100644 --- a/editor/gui/scene_tree_editor.cpp +++ b/editor/gui/scene_tree_editor.cpp @@ -1177,7 +1177,7 @@ void SceneTreeEditor::_edited() { ERR_FAIL_NULL(edited); if (is_scene_tree_dock && tree->get_next_selected(which)) { - List nodes_to_rename; + LocalVector nodes_to_rename; for (TreeItem *item = which; item; item = tree->get_next_selected(item)) { Node *n = get_node(item->get_metadata(0)); ERR_FAIL_NULL(n); @@ -1186,7 +1186,7 @@ void SceneTreeEditor::_edited() { ERR_FAIL_COND(nodes_to_rename.is_empty()); EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); - undo_redo->create_action(TTR("Rename Nodes"), UndoRedo::MERGE_DISABLE, nodes_to_rename.front()->get(), true); + undo_redo->create_action(TTR("Rename Nodes"), UndoRedo::MERGE_DISABLE, nodes_to_rename[0], true); TreeItem *item = which; String new_name = edited->get_text(0); diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp index d72c15bc2ac2..4e1849f0c07a 100644 --- a/editor/import/resource_importer_texture.cpp +++ b/editor/import/resource_importer_texture.cpp @@ -496,7 +496,7 @@ Error ResourceImporterTexture::import(ResourceUID::ID p_source_id, const String bool convert_editor_colors = p_options.has("editor/convert_colors_with_editor_theme") && p_options["editor/convert_colors_with_editor_theme"]; // Start importing images. - List> images_imported; + LocalVector> images_imported; // Load the normal image. Ref normal_image; diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 175aab05fbd7..3a6e61644bd7 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -543,7 +543,7 @@ void AnimationNodeBlendTreeEditor::_delete_nodes_request(const TypedArray to_erase; + LocalVector to_erase; if (p_nodes.is_empty()) { for (int i = 0; i < graph->get_child_count(); i++) { diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index 7c9c003ea1f1..d8091afa8d6f 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -948,7 +948,7 @@ void EditorAssetLibrary::_update_image_queue() { const int max_images = 6; int current_images = 0; - List to_delete; + LocalVector to_delete; for (KeyValue &E : image_queue) { if (!E.value.active && current_images < max_images) { String cache_filename_base = EditorPaths::get_singleton()->get_cache_dir().path_join("assetimage_" + E.value.image_url.md5_text()); @@ -973,10 +973,9 @@ void EditorAssetLibrary::_update_image_queue() { } } - while (to_delete.size()) { - image_queue[to_delete.front()->get()].request->queue_free(); - image_queue.erase(to_delete.front()->get()); - to_delete.pop_front(); + for (const int &key : to_delete) { + image_queue[key].request->queue_free(); + image_queue.erase(key); } } diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 82c2e3e4bd6c..0185703e4917 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -880,7 +880,7 @@ void CanvasItemEditor::_restore_canvas_item_state(const List &p_ca } void CanvasItemEditor::_commit_canvas_item_state(const List &p_canvas_items, const String &action_name, bool commit_bones) { - List modified_canvas_items; + LocalVector modified_canvas_items; for (CanvasItem *ci : p_canvas_items) { Dictionary old_state = editor_selection->get_node_editor_data(ci)->undo_state; Dictionary new_state = ci->_edit_get_state(); @@ -3841,7 +3841,7 @@ void CanvasItemEditor::_draw_invisible_nodes_positions(Node *p_node, const Trans } void CanvasItemEditor::_draw_hover() { - List previous_rects; + LocalVector previous_rects; Vector2 icon_size = Vector2(1, 1) * get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor)); for (int i = 0; i < hovering_results.size(); i++) { @@ -4386,7 +4386,7 @@ void CanvasItemEditor::_insert_animation_keys(bool p_location, bool p_rotation, if (n2d->has_meta("_edit_bone_") && n2d->get_parent_item()) { //look for an IK chain - List ik_chain; + LocalVector ik_chain; Node2D *n = Object::cast_to(n2d->get_parent_item()); bool has_chain = false; diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp index 1f587e557ff1..1646b3386777 100644 --- a/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/editor/plugins/resource_preloader_editor_plugin.cpp @@ -183,7 +183,7 @@ void ResourcePreloaderEditor::_update_library() { List rnames; preloader->get_resource_list(&rnames); - List names; + LocalVector names; for (const StringName &E : rnames) { names.push_back(E); } diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 1cab950d0241..a6f7c6922f3e 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -342,7 +342,7 @@ class EditorScriptCodeCompletionCache : public ScriptCodeCompletionCache { uint32_t max_cache_size = 128; void cleanup() { - List to_clean; + LocalVector to_clean; HashMap::Iterator I = cached.begin(); while (I) { @@ -352,9 +352,8 @@ class EditorScriptCodeCompletionCache : public ScriptCodeCompletionCache { ++I; } - while (to_clean.front()) { - cached.erase(to_clean.front()->get()); - to_clean.pop_front(); + for (String &E : to_clean) { + cached.erase(E); } } diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index c2f6896e3dcc..bc8827ab4ea6 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -68,7 +68,7 @@ void ThemeItemImportTree::_update_items_tree() { List types; List names; - List filtered_names; + LocalVector filtered_names; base_theme->get_type_list(&types); types.sort_custom(); diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 1162943b4a8e..938dfe6c8436 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -4420,13 +4420,13 @@ void VisualShaderEditor::_delete_nodes(int p_type, const List &p_nodes) { } } - List used_conns; + LocalVector used_conns; for (const int &F : p_nodes) { for (const VisualShader::Connection &E : conns) { if (E.from_node == F || E.to_node == F) { bool cancel = false; - for (List::Element *R = used_conns.front(); R; R = R->next()) { - if (R->get().from_node == E.from_node && R->get().from_port == E.from_port && R->get().to_node == E.to_node && R->get().to_port == E.to_port) { + for (VisualShader::Connection &R : used_conns) { + if (R.from_node == E.from_node && R.from_port == E.from_port && R.to_node == E.to_node && R.to_port == E.to_port) { cancel = true; // to avoid ERR_ALREADY_EXISTS warning break; } @@ -4812,8 +4812,8 @@ void VisualShaderEditor::_graph_gui_input(const Ref &p_event) { selected_frame = -1; selected_float_constant = -1; - List selected_deletable_graph_elements; - List selected_graph_elements; + LocalVector selected_deletable_graph_elements; + LocalVector selected_graph_elements; for (int i = 0; i < graph->get_child_count(); i++) { GraphElement *graph_element = Object::cast_to(graph->get_child(i)); if (!graph_element) { diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 20a7faadc4dc..be118a5e1fb7 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -662,7 +662,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { ERR_CONTINUE(!dup); // Preserve ownership relations ready for pasting. - List owned; + LocalVector owned; Node *owner = node; while (owner) { List cur_owned; @@ -892,7 +892,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { for (Node *node : selection) { Node *parent = node->get_parent(); - List owned; + LocalVector owned; Node *owner = node; while (owner) { List cur_owned; @@ -2575,7 +2575,7 @@ void SceneTreeDock::_toggle_placeholder_from_selection() { } void SceneTreeDock::_reparent_nodes_to_root(Node *p_root, const Array &p_nodes, Node *p_owner) { - List nodes; + LocalVector nodes; for (int i = 0; i < p_nodes.size(); i++) { Node *node = Object::cast_to(p_nodes[i]); ERR_FAIL_NULL(node); @@ -3144,7 +3144,7 @@ void SceneTreeDock::_replace_node(Node *p_node, Node *p_by_node, bool p_keep_pro String newname = oldnode->get_name(); - List to_erase; + LocalVector to_erase; for (int i = 0; i < oldnode->get_child_count(); i++) { if (oldnode->get_child(i)->get_owner() == nullptr && oldnode->is_owned_by_parent()) { to_erase.push_back(oldnode->get_child(i)); @@ -3178,9 +3178,8 @@ void SceneTreeDock::_replace_node(Node *p_node, Node *p_by_node, bool p_keep_pro if (p_remove_old) { memdelete(oldnode); - while (to_erase.front()) { - memdelete(to_erase.front()->get()); - to_erase.pop_front(); + for (Node *&oldnode_child : to_erase) { + memdelete(oldnode_child); } } } diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index a638adeaee99..ed9701cf1332 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -1281,7 +1281,7 @@ RBSet GDScript::get_dependencies() { HashMap> GDScript::get_all_dependencies() { HashMap> all_dependencies; - List scripts; + LocalVector scripts; { MutexLock lock(GDScriptLanguage::singleton->mutex); @@ -2583,7 +2583,7 @@ void GDScriptLanguage::reload_all_scripts() { void GDScriptLanguage::reload_scripts(const Array &p_scripts, bool p_soft_reload) { #ifdef DEBUG_ENABLED - List> scripts; + LocalVector> scripts; { MutexLock lock(mutex); diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp index 372c212d2ba0..135b7c7588e1 100644 --- a/modules/gdscript/gdscript_function.cpp +++ b/modules/gdscript/gdscript_function.cpp @@ -85,7 +85,7 @@ void GDScriptFunction::debug_get_stack_member_state(int p_line, List stackpositions; + LocalVector<_GDFKCS> stackpositions; for (const KeyValue &E : sdmap) { _GDFKCS spp; spp.id = E.key; diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 0c56cb2654f3..1ee324cc5f0d 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -2189,7 +2189,7 @@ GDScriptParser::MatchNode *GDScriptParser::parse_match() { bool all_have_return = true; bool have_wildcard = false; - List match_branch_annotation_stack; + LocalVector match_branch_annotation_stack; while (!check(GDScriptTokenizer::Token::DEDENT) && !is_at_end()) { if (match(GDScriptTokenizer::Token::PASS)) { diff --git a/modules/mono/class_db_api_json.cpp b/modules/mono/class_db_api_json.cpp index 04af60e22ffa..d27539671d52 100644 --- a/modules/mono/class_db_api_json.cpp +++ b/modules/mono/class_db_api_json.cpp @@ -59,7 +59,7 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) { { //methods - List snames; + LocalVector snames; for (const KeyValue &F : t->method_map) { String name = F.key.operator String(); @@ -122,7 +122,7 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) { { //constants - List snames; + LocalVector snames; for (const KeyValue &F : t->constant_map) { snames.push_back(F.key); @@ -147,7 +147,7 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) { { //signals - List snames; + LocalVector snames; for (const KeyValue &F : t->signal_map) { snames.push_back(F.key); @@ -180,7 +180,7 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) { { //properties - List snames; + LocalVector snames; for (const KeyValue &F : t->property_setget) { snames.push_back(F.key); diff --git a/modules/multiplayer/scene_replication_interface.cpp b/modules/multiplayer/scene_replication_interface.cpp index edc66c876c31..b3e49169800a 100644 --- a/modules/multiplayer/scene_replication_interface.cpp +++ b/modules/multiplayer/scene_replication_interface.cpp @@ -491,7 +491,7 @@ Error SceneReplicationInterface::_make_spawn_packet(Node *p_node, MultiplayerSpa // Prepare spawn state. List state_props; - List sync_ids; + LocalVector sync_ids; const HashSet synchronizers = tnode->synchronizers; for (const ObjectID &sid : synchronizers) { MultiplayerSynchronizer *sync = get_id_as(sid); diff --git a/modules/webrtc/webrtc_multiplayer_peer.cpp b/modules/webrtc/webrtc_multiplayer_peer.cpp index 45fa9f46ca46..0ad3eacd8f6c 100644 --- a/modules/webrtc/webrtc_multiplayer_peer.cpp +++ b/modules/webrtc/webrtc_multiplayer_peer.cpp @@ -71,8 +71,8 @@ void WebRTCMultiplayerPeer::poll() { return; } - List remove; - List add; + LocalVector remove; + LocalVector add; for (KeyValue> &E : peer_map) { Ref peer = E.value; peer->connection->poll(); diff --git a/modules/zip/zip_reader.cpp b/modules/zip/zip_reader.cpp index 76f48edb6921..db9f0a525bcf 100644 --- a/modules/zip/zip_reader.cpp +++ b/modules/zip/zip_reader.cpp @@ -68,7 +68,7 @@ PackedStringArray ZIPReader::get_files() { err = unzGoToFirstFile(uzf); ERR_FAIL_COND_V(err != UNZ_OK, PackedStringArray()); - List s; + LocalVector s; do { unz_file_info64 file_info; String filepath; @@ -82,8 +82,8 @@ PackedStringArray ZIPReader::get_files() { PackedStringArray arr; arr.resize(s.size()); int idx = 0; - for (const List::Element *E = s.front(); E; E = E->next()) { - arr.set(idx++, E->get()); + for (const String &E : s) { + arr.set(idx++, E); } return arr; } diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp index b2f847a1480e..8fc2ea580fc5 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -1744,7 +1744,7 @@ bool AnimationNodeBlendTree::_get(const StringName &p_name, Variant &r_ret) cons } void AnimationNodeBlendTree::_get_property_list(List *p_list) const { - List names; + LocalVector names; for (const KeyValue &E : nodes) { names.push_back(E.key); } diff --git a/scene/animation/animation_mixer.cpp b/scene/animation/animation_mixer.cpp index 0a798670062b..e0152279e520 100644 --- a/scene/animation/animation_mixer.cpp +++ b/scene/animation/animation_mixer.cpp @@ -392,7 +392,7 @@ void AnimationMixer::rename_animation_library(const StringName &p_name, const St } void AnimationMixer::get_animation_list(List *p_animations) const { - List anims; + LocalVector anims; for (const KeyValue &E : animation_set) { anims.push_back(E.key); } diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp index 844cc9d6222a..9b2a97598c38 100644 --- a/scene/animation/animation_node_state_machine.cpp +++ b/scene/animation/animation_node_state_machine.cpp @@ -1211,10 +1211,10 @@ AnimationNodeStateMachinePlayback::AnimationNodeStateMachinePlayback() { void AnimationNodeStateMachine::get_parameter_list(List *r_list) const { AnimationNode::get_parameter_list(r_list); r_list->push_back(PropertyInfo(Variant::OBJECT, playback, PROPERTY_HINT_RESOURCE_TYPE, "AnimationNodeStateMachinePlayback", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_ALWAYS_DUPLICATE)); // Don't store this object in .tres, it always needs to be made as unique object. - List advance_conditions; + LocalVector advance_conditions; for (int i = 0; i < transitions.size(); i++) { StringName ac = transitions[i].transition->get_advance_condition_name(); - if (ac != StringName() && advance_conditions.find(ac) == nullptr) { + if (ac != StringName() && advance_conditions.find(ac) == -1) { advance_conditions.push_back(ac); } } @@ -1428,7 +1428,7 @@ void AnimationNodeStateMachine::_rename_transitions(const StringName &p_name, co } void AnimationNodeStateMachine::get_node_list(List *r_nodes) const { - List nodes; + LocalVector nodes; for (const KeyValue &E : states) { nodes.push_back(E.key); } @@ -1582,13 +1582,6 @@ void AnimationNodeStateMachine::remove_transition_by_index(const int p_transitio Transition tr = transitions[p_transition]; transitions.write[p_transition].transition->disconnect("advance_condition_changed", callable_mp(this, &AnimationNodeStateMachine::_tree_changed)); transitions.remove_at(p_transition); - - Vector path_from = String(tr.from).split("/"); - Vector path_to = String(tr.to).split("/"); - - List> paths; - paths.push_back(path_from); - paths.push_back(path_to); } void AnimationNodeStateMachine::_remove_transition(const Ref p_transition) { @@ -1704,7 +1697,7 @@ bool AnimationNodeStateMachine::_get(const StringName &p_name, Variant &r_ret) c } void AnimationNodeStateMachine::_get_property_list(List *p_list) const { - List names; + LocalVector names; for (const KeyValue &E : states) { names.push_back(E.key); } diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 8d24859422ec..c2804550e620 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -130,7 +130,7 @@ void AnimationPlayer::_validate_property(PropertyInfo &p_property) const { } void AnimationPlayer::_get_property_list(List *p_list) const { - List anim_names; + LocalVector anim_names; for (const KeyValue &E : animation_set) { AHashMap::ConstIterator F = animation_next_set.find(E.key); @@ -282,7 +282,7 @@ void AnimationPlayer::_blend_playback_data(double p_delta, bool p_started) { playback.blend.clear(); return; } - List::Element *> to_erase; + LocalVector::Element *> to_erase; for (List::Element *E = c.blend.front(); E; E = E->next()) { Blend &b = E->get(); b.blend_left = MAX(0, b.blend_left - Math::absf(speed_scale * p_delta) / b.blend_time); @@ -896,7 +896,7 @@ void AnimationPlayer::_animation_removed(const StringName &p_name, const StringN _animation_set_cache_update(); // Erase blends if needed - List to_erase; + LocalVector to_erase; for (const KeyValue &E : blend_times) { BlendKey bk = E.key; if (bk.from == name || bk.to == name) { @@ -904,9 +904,8 @@ void AnimationPlayer::_animation_removed(const StringName &p_name, const StringN } } - while (to_erase.size()) { - blend_times.erase(to_erase.front()->get()); - to_erase.pop_front(); + for (const BlendKey &bk : to_erase) { + blend_times.erase(bk); } } @@ -914,7 +913,7 @@ void AnimationPlayer::_rename_animation(const StringName &p_from_name, const Str AnimationMixer::_rename_animation(p_from_name, p_to_name); // Rename autoplay or blends if needed. - List to_erase; + LocalVector to_erase; HashMap to_insert; for (const KeyValue &E : blend_times) { BlendKey bk = E.key; @@ -935,9 +934,8 @@ void AnimationPlayer::_rename_animation(const StringName &p_from_name, const Str } } - while (to_erase.size()) { - blend_times.erase(to_erase.front()->get()); - to_erase.pop_front(); + for (const BlendKey &bk : to_erase) { + blend_times.erase(bk); } while (to_insert.size()) { diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index cbd51ca69456..43530c6d70d1 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -3678,7 +3678,7 @@ void CodeEdit::_text_changed() { line_number_digits = new_line_number_digits; _update_line_number_gutter_width(); - List breakpoints; + LocalVector breakpoints; for (const KeyValue &E : breakpointed_lines) { breakpoints.push_back(E.key); } diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 515c33a45477..fe4902f8c3c7 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -226,7 +226,7 @@ void Control::get_argument_options(const StringName &p_function, int p_idx, List List theme_items; ThemeDB::get_singleton()->get_class_items(get_class_name(), &theme_items, true, type); - List sn; + LocalVector sn; for (const ThemeDB::ThemeItemBind &E : theme_items) { if (E.data_type == type) { sn.push_back(E.item_name); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 5512e74c0435..5177031857f4 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -806,7 +806,7 @@ void FileDialog::update_file_list() { String filename_filter_lower = file_name_filter.to_lower(); - List patterns; + LocalVector patterns; // build filter if (filter->get_selected() == filter->get_item_count() - 1) { // match all diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index bcf0f5bdc89f..8c1b6e421536 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -1362,7 +1362,7 @@ void GraphEdit::_draw_minimap_connection_line(const Vector2 &p_from_graph_positi void GraphEdit::_update_connections() { // Collect all dead connections and remove them. - List>::Element *> dead_connections; + LocalVector>::Element *> dead_connections; for (List>::Element *E = connections.front(); E; E = E->next()) { Ref &c = E->get(); diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 43a781a2309e..a653f13195ac 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -2758,7 +2758,7 @@ Node *Node::_duplicate(int p_flags, HashMap *r_duplimap) c node->data.editable_instance = data.editable_instance; } - List hidden_roots; + LocalVector hidden_roots; List node_tree; node_tree.push_front(this); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 06724b461fa5..6defe3b57dd8 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -3925,8 +3925,8 @@ void Viewport::_camera_2d_set(Camera2D *p_camera_2d) { } void Viewport::_cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paused_only, uint64_t p_frame_reference) { - List to_erase; - List to_mouse_exit; + LocalVector to_erase; + LocalVector to_mouse_exit; for (const KeyValue &E : physics_2d_mouseover) { if (!p_clean_all_frames && E.value == p_frame_reference) { @@ -3946,14 +3946,13 @@ void Viewport::_cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paus to_erase.push_back(E.key); } - while (to_erase.size()) { - physics_2d_mouseover.erase(to_erase.front()->get()); - to_erase.pop_front(); + for (ObjectID &E : to_erase) { + physics_2d_mouseover.erase(E); } // Per-shape. - List> shapes_to_erase; - List> shapes_to_mouse_exit; + LocalVector> shapes_to_erase; + LocalVector> shapes_to_mouse_exit; for (KeyValue, uint64_t> &E : physics_2d_shape_mouseover) { if (!p_clean_all_frames && E.value == p_frame_reference) { @@ -3973,24 +3972,20 @@ void Viewport::_cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paus shapes_to_erase.push_back(E.key); } - while (shapes_to_erase.size()) { - physics_2d_shape_mouseover.erase(shapes_to_erase.front()->get()); - shapes_to_erase.pop_front(); + for (Pair &E : shapes_to_erase) { + physics_2d_shape_mouseover.erase(E); } - while (to_mouse_exit.size()) { - Object *o = ObjectDB::get_instance(to_mouse_exit.front()->get()); + for (ObjectID &E : to_mouse_exit) { + Object *o = ObjectDB::get_instance(E); CollisionObject2D *co = Object::cast_to(o); co->_mouse_exit(); - to_mouse_exit.pop_front(); } - while (shapes_to_mouse_exit.size()) { - Pair e = shapes_to_mouse_exit.front()->get(); - Object *o = ObjectDB::get_instance(e.first); + for (Pair &E : shapes_to_mouse_exit) { + Object *o = ObjectDB::get_instance(E.first); CollisionObject2D *co = Object::cast_to(o); - co->_mouse_shape_exit(e.second); - shapes_to_mouse_exit.pop_front(); + co->_mouse_shape_exit(E.second); } } diff --git a/scene/resources/animation_library.cpp b/scene/resources/animation_library.cpp index ce350977c659..6df79efe594d 100644 --- a/scene/resources/animation_library.cpp +++ b/scene/resources/animation_library.cpp @@ -112,7 +112,7 @@ void AnimationLibrary::_animation_changed(const StringName &p_name) { } void AnimationLibrary::get_animation_list(List *p_animations) const { - List anims; + LocalVector anims; for (const KeyValue> &E : animations) { anims.push_back(E.key); diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index d6748ed2e64f..3cf6b407fe6e 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -126,7 +126,7 @@ Ref SceneState::get_remap_resource(const Ref &p_resource, Ha Node *SceneState::instantiate(GenEditState p_edit_state) const { // Nodes where instantiation failed (because something is missing.) - List stray_instances; + LocalVector stray_instances; #define NODE_FROM_ID(p_name, p_id) \ Node *p_name; \ @@ -612,9 +612,8 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const { //Node *s = ret_nodes[0]; //remove nodes that could not be added, likely as a result that - while (stray_instances.size()) { - memdelete(stray_instances.front()->get()); - stray_instances.pop_front(); + for (Node *&node : stray_instances) { + memdelete(node); } for (int i = 0; i < editable_instances.size(); i++) { diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index fa2c01d354d7..232b87380402 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -1604,9 +1604,6 @@ String VisualShader::validate_port_name(const String &p_port_name, VisualShaderN return String(); } - List input_names; - List output_names; - for (int i = 0; i < p_node->get_input_port_count(); i++) { if (!p_output && i == p_port_id) { continue; @@ -2594,7 +2591,7 @@ void VisualShader::_update_shader() const { String global_expressions; HashSet used_parameter_names; - List parameters; + LocalVector parameters; HashMap> emitters; HashMap> varying_setters; @@ -2639,7 +2636,7 @@ void VisualShader::_update_shader() const { } int idx = 0; - for (List::Iterator itr = parameters.begin(); itr != parameters.end(); ++itr, ++idx) { + for (LocalVector::Iterator itr = parameters.begin(); itr != parameters.end(); ++itr, ++idx) { VisualShaderNodeParameter *parameter = *itr; if (used_parameter_names.has(parameter->get_parameter_name())) { global_code += parameter->generate_global(get_mode(), Type(idx), -1); diff --git a/servers/rendering/renderer_rd/storage_rd/material_storage.cpp b/servers/rendering/renderer_rd/storage_rd/material_storage.cpp index e84bc399bfd1..d6c186c3504e 100644 --- a/servers/rendering/renderer_rd/storage_rd/material_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/material_storage.cpp @@ -1037,7 +1037,7 @@ void MaterialStorage::MaterialData::update_textures(const HashMap to_delete; + LocalVector to_delete; for (KeyValue &E : used_global_textures) { if (E.value != global_textures_pass) { to_delete.push_back(E.key); @@ -1049,10 +1049,10 @@ void MaterialStorage::MaterialData::update_textures(const HashMapget()); - to_delete.pop_front(); + for (StringName &name : to_delete) { + used_global_textures.erase(name); } + //handle registering/unregistering global textures if (uses_global_textures != (global_texture_E != nullptr)) { if (uses_global_textures) { diff --git a/servers/rendering/shader_compiler.cpp b/servers/rendering/shader_compiler.cpp index e5e095c7a193..e2fcd658062b 100644 --- a/servers/rendering/shader_compiler.cpp +++ b/servers/rendering/shader_compiler.cpp @@ -660,7 +660,7 @@ String ShaderCompiler::_dump_node_code(const SL::Node *p_node, int p_level, Gene uint32_t index = p_default_actions.base_varying_index; - List> var_frag_to_light; + LocalVector> var_frag_to_light; Vector varying_names; diff --git a/thirdparty/enet/godot.cpp b/thirdparty/enet/godot.cpp index 9e766e52c3ea..25ab6fce08c1 100644 --- a/thirdparty/enet/godot.cpp +++ b/thirdparty/enet/godot.cpp @@ -335,7 +335,7 @@ class ENetDTLSServer : public ENetGodotSocket { } } - List remove; + LocalVector remove; Error err = ERR_BUSY; // TODO this needs to be fair! From 66b66dd11428bafa1aa0f8b07281d0d9bd93b067 Mon Sep 17 00:00:00 2001 From: Yufeng Ying Date: Thu, 12 Dec 2024 17:16:06 +0800 Subject: [PATCH 2/2] Add reserve where appropriate. --- core/io/packed_data_container.cpp | 1 + core/object/class_db.cpp | 4 ++++ core/object/script_language.cpp | 1 + editor/animation_bezier_editor.cpp | 2 ++ editor/animation_track_editor.cpp | 1 + editor/debugger/script_editor_debugger.cpp | 1 + editor/plugins/canvas_item_editor_plugin.cpp | 1 + editor/plugins/resource_preloader_editor_plugin.cpp | 1 + editor/scene_tree_dock.cpp | 1 + modules/gdscript/gdscript_function.cpp | 1 + modules/mono/class_db_api_json.cpp | 3 +++ scene/animation/animation_blend_tree.cpp | 1 + scene/animation/animation_mixer.cpp | 1 + scene/animation/animation_node_state_machine.cpp | 2 ++ scene/gui/code_edit.cpp | 1 + scene/resources/animation_library.cpp | 1 + 16 files changed, 23 insertions(+) diff --git a/core/io/packed_data_container.cpp b/core/io/packed_data_container.cpp index 2fb404e56ac5..e3a32c370164 100644 --- a/core/io/packed_data_container.cpp +++ b/core/io/packed_data_container.cpp @@ -271,6 +271,7 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector &tmpd List keys; d.get_key_list(&keys); LocalVector sortk; + sortk.reserve(keys.size()); for (const Variant &key : keys) { DictKey dk; diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index c5e66788d9c9..4bd320d44504 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -382,6 +382,7 @@ uint32_t ClassDB::get_api_hash(APIType p_api) { uint64_t hash = hash_murmur3_one_64(HashMapHasherDefault::hash(VERSION_FULL_CONFIG)); LocalVector class_list; + class_list.reserve(classes.size()); for (const KeyValue &E : classes) { class_list.push_back(E.key); } @@ -445,6 +446,7 @@ uint32_t ClassDB::get_api_hash(APIType p_api) { { //constants LocalVector snames; + snames.reserve(t->constant_map.size()); for (const KeyValue &F : t->constant_map) { snames.push_back(F.key); @@ -461,6 +463,7 @@ uint32_t ClassDB::get_api_hash(APIType p_api) { { //signals LocalVector snames; + snames.reserve(t->signal_map.size()); for (const KeyValue &F : t->signal_map) { snames.push_back(F.key); @@ -480,6 +483,7 @@ uint32_t ClassDB::get_api_hash(APIType p_api) { { //properties LocalVector snames; + snames.reserve(t->property_setget.size()); for (const KeyValue &F : t->property_setget) { snames.push_back(F.key); diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp index 0f315001ffed..99c36401a797 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -484,6 +484,7 @@ StringName ScriptServer::get_global_class_native_base(const String &p_class) { void ScriptServer::get_global_class_list(List *r_global_classes) { LocalVector classes; + classes.reserve(r_global_classes->size()); for (const KeyValue &E : global_classes) { classes.push_back(E.key); } diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index b3c9d40e7305..4dc249e6408b 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -1746,6 +1746,7 @@ void AnimationBezierTrackEdit::duplicate_selected_keys(real_t p_ofs, bool p_ofs_ undo_redo->create_action(TTR("Animation Duplicate Keys")); LocalVector> new_selection_values; + new_selection_values.reserve(selection.size()); for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) { real_t t = animation->track_get_key_time(E->get().first, E->get().second); @@ -1884,6 +1885,7 @@ void AnimationBezierTrackEdit::paste_keys(real_t p_ofs, bool p_ofs_valid) { } LocalVector> new_selection_values; + new_selection_values.reserve(editor->key_clipboard.keys.size()); for (int i = 0; i < editor->key_clipboard.keys.size(); i++) { const AnimationTrackEditor::KeyClipboard::Key key = editor->key_clipboard.keys[i]; diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 82353c42e7d8..f6da742c69db 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -6296,6 +6296,7 @@ void AnimationTrackEditor::_anim_paste_keys(float p_ofs, bool p_ofs_valid, int p EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); undo_redo->create_action(TTR("Animation Paste Keys")); LocalVector> new_selection_values; + new_selection_values.reserve(key_clipboard.keys.size()); for (int i = 0; i < key_clipboard.keys.size(); i++) { const KeyClipboard::Key key = key_clipboard.keys[i]; diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index cb86601c61bb..100791cb6dc9 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -1741,6 +1741,7 @@ void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) { // Store first else we will be removing as we loop. LocalVector lines; + lines.reserve(file_item->get_child_count()); for (TreeItem *breakpoint_item = file_item->get_first_child(); breakpoint_item; breakpoint_item = breakpoint_item->get_next()) { lines.push_back(breakpoint_item->get_meta("line")); } diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 0185703e4917..f903bc7db443 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -3842,6 +3842,7 @@ void CanvasItemEditor::_draw_invisible_nodes_positions(Node *p_node, const Trans void CanvasItemEditor::_draw_hover() { LocalVector previous_rects; + previous_rects.reserve(hovering_results.size()); Vector2 icon_size = Vector2(1, 1) * get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor)); for (int i = 0; i < hovering_results.size(); i++) { diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp index 1646b3386777..cd229ff45374 100644 --- a/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/editor/plugins/resource_preloader_editor_plugin.cpp @@ -184,6 +184,7 @@ void ResourcePreloaderEditor::_update_library() { preloader->get_resource_list(&rnames); LocalVector names; + names.reserve(rnames.size()); for (const StringName &E : rnames) { names.push_back(E); } diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index be118a5e1fb7..231b25787051 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -2576,6 +2576,7 @@ void SceneTreeDock::_toggle_placeholder_from_selection() { void SceneTreeDock::_reparent_nodes_to_root(Node *p_root, const Array &p_nodes, Node *p_owner) { LocalVector nodes; + nodes.reserve(p_nodes.size()); for (int i = 0; i < p_nodes.size(); i++) { Node *node = Object::cast_to(p_nodes[i]); ERR_FAIL_NULL(node); diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp index 135b7c7588e1..c39786a4dca2 100644 --- a/modules/gdscript/gdscript_function.cpp +++ b/modules/gdscript/gdscript_function.cpp @@ -86,6 +86,7 @@ void GDScriptFunction::debug_get_stack_member_state(int p_line, List stackpositions; + stackpositions.reserve(sdmap.size()); for (const KeyValue &E : sdmap) { _GDFKCS spp; spp.id = E.key; diff --git a/modules/mono/class_db_api_json.cpp b/modules/mono/class_db_api_json.cpp index d27539671d52..0139ea87635b 100644 --- a/modules/mono/class_db_api_json.cpp +++ b/modules/mono/class_db_api_json.cpp @@ -123,6 +123,7 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) { { //constants LocalVector snames; + snames.reserve(t->constant_map.size()); for (const KeyValue &F : t->constant_map) { snames.push_back(F.key); @@ -148,6 +149,7 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) { { //signals LocalVector snames; + snames.reserve(t->signal_map.size()); for (const KeyValue &F : t->signal_map) { snames.push_back(F.key); @@ -181,6 +183,7 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) { { //properties LocalVector snames; + snames.reserve(t->property_setget.size()); for (const KeyValue &F : t->property_setget) { snames.push_back(F.key); diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp index 8fc2ea580fc5..176cc5f0d61e 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -1745,6 +1745,7 @@ bool AnimationNodeBlendTree::_get(const StringName &p_name, Variant &r_ret) cons void AnimationNodeBlendTree::_get_property_list(List *p_list) const { LocalVector names; + names.reserve(nodes.size()); for (const KeyValue &E : nodes) { names.push_back(E.key); } diff --git a/scene/animation/animation_mixer.cpp b/scene/animation/animation_mixer.cpp index e0152279e520..6bf20df3fa2a 100644 --- a/scene/animation/animation_mixer.cpp +++ b/scene/animation/animation_mixer.cpp @@ -393,6 +393,7 @@ void AnimationMixer::rename_animation_library(const StringName &p_name, const St void AnimationMixer::get_animation_list(List *p_animations) const { LocalVector anims; + anims.reserve(animation_set.size()); for (const KeyValue &E : animation_set) { anims.push_back(E.key); } diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp index 9b2a97598c38..fc47c19b52c6 100644 --- a/scene/animation/animation_node_state_machine.cpp +++ b/scene/animation/animation_node_state_machine.cpp @@ -1429,6 +1429,7 @@ void AnimationNodeStateMachine::_rename_transitions(const StringName &p_name, co void AnimationNodeStateMachine::get_node_list(List *r_nodes) const { LocalVector nodes; + nodes.reserve(states.size()); for (const KeyValue &E : states) { nodes.push_back(E.key); } @@ -1698,6 +1699,7 @@ bool AnimationNodeStateMachine::_get(const StringName &p_name, Variant &r_ret) c void AnimationNodeStateMachine::_get_property_list(List *p_list) const { LocalVector names; + names.reserve(states.size()); for (const KeyValue &E : states) { names.push_back(E.key); } diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 43530c6d70d1..cafb1fa125a8 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -3679,6 +3679,7 @@ void CodeEdit::_text_changed() { _update_line_number_gutter_width(); LocalVector breakpoints; + breakpoints.reserve(breakpointed_lines.size()); for (const KeyValue &E : breakpointed_lines) { breakpoints.push_back(E.key); } diff --git a/scene/resources/animation_library.cpp b/scene/resources/animation_library.cpp index 6df79efe594d..442382c6de6c 100644 --- a/scene/resources/animation_library.cpp +++ b/scene/resources/animation_library.cpp @@ -113,6 +113,7 @@ void AnimationLibrary::_animation_changed(const StringName &p_name) { void AnimationLibrary::get_animation_list(List *p_animations) const { LocalVector anims; + anims.reserve(animations.size()); for (const KeyValue> &E : animations) { anims.push_back(E.key);