From 754d49ac8151bc4e43f949c61102c157610c13a9 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Fri, 26 Sep 2025 19:13:23 -0700 Subject: [PATCH] Skip copying values constructed immediately before returning --- .../debugger/editor_expression_evaluator.cpp | 3 +-- editor/debugger/script_editor_debugger.cpp | 3 +-- .../scene/2d/tiles/tile_map_layer_editor.cpp | 3 +-- .../2d/tiles/tile_set_atlas_source_editor.cpp | 9 +++---- modules/enet/enet_connection.cpp | 2 +- .../gdscript_extend_parser.cpp | 5 ++-- .../gdscript_text_document.cpp | 12 +++------ modules/gdscript/language_server/godot_lsp.h | 6 ++--- modules/regex/regex.cpp | 2 +- scene/2d/tile_map.cpp | 12 +++------ scene/2d/tile_map_layer.cpp | 26 ++++++++----------- scene/main/resource_preloader.cpp | 3 +-- scene/resources/2d/tile_set.cpp | 6 ++--- servers/debugger/servers_debugger.cpp | 3 +-- 14 files changed, 35 insertions(+), 60 deletions(-) diff --git a/editor/debugger/editor_expression_evaluator.cpp b/editor/debugger/editor_expression_evaluator.cpp index 9fe5137a351..73edbba215b 100644 --- a/editor/debugger/editor_expression_evaluator.cpp +++ b/editor/debugger/editor_expression_evaluator.cpp @@ -76,8 +76,7 @@ void EditorExpressionEvaluator::_clear() { } void EditorExpressionEvaluator::_remote_object_selected(ObjectID p_id) { - Array arr = { p_id }; - editor_debugger->emit_signal(SNAME("remote_objects_requested"), arr); + editor_debugger->emit_signal(SNAME("remote_objects_requested"), Array{ p_id }); } void EditorExpressionEvaluator::_on_expression_input_changed(const String &p_expression) { diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp index 212b1c66663..007adb49ace 100644 --- a/editor/debugger/script_editor_debugger.cpp +++ b/editor/debugger/script_editor_debugger.cpp @@ -288,8 +288,7 @@ void ScriptEditorDebugger::clear_inspector(bool p_send_msg) { } void ScriptEditorDebugger::_remote_object_selected(ObjectID p_id) { - Array arr = { p_id }; - emit_signal(SNAME("remote_objects_requested"), arr); + emit_signal(SNAME("remote_objects_requested"), Array{ p_id }); } void ScriptEditorDebugger::_remote_objects_edited(const String &p_prop, const TypedDictionary &p_values, const String &p_field) { diff --git a/editor/scene/2d/tiles/tile_map_layer_editor.cpp b/editor/scene/2d/tiles/tile_map_layer_editor.cpp index e8fd7481a34..9fcfd11c499 100644 --- a/editor/scene/2d/tiles/tile_map_layer_editor.cpp +++ b/editor/scene/2d/tiles/tile_map_layer_editor.cpp @@ -1114,8 +1114,7 @@ HashMap TileMapLayerEditorTilesPlugin::_draw_rect(Vector2 // Get or create the pattern. Ref pattern = p_erase ? erase_pattern : selection_pattern; - HashMap err_output; - ERR_FAIL_COND_V(pattern->is_empty(), err_output); + ERR_FAIL_COND_V(pattern->is_empty(), (HashMap())); // Compute the offset to align things to the bottom or right. bool aligned_right = p_end_cell.x < p_start_cell.x; diff --git a/editor/scene/2d/tiles/tile_set_atlas_source_editor.cpp b/editor/scene/2d/tiles/tile_set_atlas_source_editor.cpp index 6482b00aaf3..869c20c092e 100644 --- a/editor/scene/2d/tiles/tile_set_atlas_source_editor.cpp +++ b/editor/scene/2d/tiles/tile_set_atlas_source_editor.cpp @@ -1476,8 +1476,7 @@ void TileSetAtlasSourceEditor::_end_dragging() { undo_redo->add_do_method(tile_set_atlas_source, "move_tile_in_atlas", drag_start_tile_shape.position, drag_current_tile, tile_set_atlas_source->get_tile_size_in_atlas(drag_current_tile)); undo_redo->add_do_method(this, "_set_selection_from_array", _get_selection_as_array()); undo_redo->add_undo_method(tile_set_atlas_source, "move_tile_in_atlas", drag_current_tile, drag_start_tile_shape.position, drag_start_tile_shape.size); - Array array = { drag_start_tile_shape.position, 0 }; - undo_redo->add_undo_method(this, "_set_selection_from_array", array); + undo_redo->add_undo_method(this, "_set_selection_from_array", Array{ drag_start_tile_shape.position, 0 }); undo_redo->commit_action(false); } break; @@ -1574,8 +1573,7 @@ void TileSetAtlasSourceEditor::_end_dragging() { undo_redo->add_do_method(tile_set_atlas_source, "move_tile_in_atlas", drag_start_tile_shape.position, drag_current_tile, tile_set_atlas_source->get_tile_size_in_atlas(drag_current_tile)); undo_redo->add_do_method(this, "_set_selection_from_array", _get_selection_as_array()); undo_redo->add_undo_method(tile_set_atlas_source, "move_tile_in_atlas", drag_current_tile, drag_start_tile_shape.position, drag_start_tile_shape.size); - Array array = { drag_start_tile_shape.position, 0 }; - undo_redo->add_undo_method(this, "_set_selection_from_array", array); + undo_redo->add_undo_method(this, "_set_selection_from_array", Array{ drag_start_tile_shape.position, 0 }); undo_redo->commit_action(false); } break; @@ -1663,8 +1661,7 @@ void TileSetAtlasSourceEditor::_menu_option(int p_option) { case TILE_CREATE: { undo_redo->create_action(TTR("Create a tile")); undo_redo->add_do_method(tile_set_atlas_source, "create_tile", menu_option_coords); - Array array = { menu_option_coords, 0 }; - undo_redo->add_do_method(this, "_set_selection_from_array", array); + undo_redo->add_do_method(this, "_set_selection_from_array", Array{ menu_option_coords, 0 }); undo_redo->add_undo_method(tile_set_atlas_source, "remove_tile", menu_option_coords); undo_redo->add_undo_method(this, "_set_selection_from_array", _get_selection_as_array()); undo_redo->commit_action(); diff --git a/modules/enet/enet_connection.cpp b/modules/enet/enet_connection.cpp index 3c4f229ab35..9b764b1ad9a 100644 --- a/modules/enet/enet_connection.cpp +++ b/modules/enet/enet_connection.cpp @@ -265,7 +265,7 @@ void ENetConnection::get_peers(List> &r_peers) { } TypedArray ENetConnection::_get_peers() { - ERR_FAIL_NULL_V_MSG(host, Array(), "The ENetConnection instance isn't currently active."); + ERR_FAIL_NULL_V_MSG(host, TypedArray(), "The ENetConnection instance isn't currently active."); TypedArray out; for (const Ref &I : peers) { out.push_back(I); diff --git a/modules/gdscript/language_server/gdscript_extend_parser.cpp b/modules/gdscript/language_server/gdscript_extend_parser.cpp index 83309547a51..8780eb0fcc7 100644 --- a/modules/gdscript/language_server/gdscript_extend_parser.cpp +++ b/modules/gdscript/language_server/gdscript_extend_parser.cpp @@ -885,8 +885,8 @@ const Array &ExtendGDScriptParser::get_member_completions() { } Dictionary ExtendGDScriptParser::dump_function_api(const GDScriptParser::FunctionNode *p_func) const { + ERR_FAIL_NULL_V(p_func, Dictionary()); Dictionary func; - ERR_FAIL_NULL_V(p_func, func); func["name"] = p_func->identifier->name; func["return_type"] = p_func->get_datatype().to_string(); func["rpc_config"] = p_func->rpc_config; @@ -909,10 +909,9 @@ Dictionary ExtendGDScriptParser::dump_function_api(const GDScriptParser::Functio } Dictionary ExtendGDScriptParser::dump_class_api(const GDScriptParser::ClassNode *p_class) const { + ERR_FAIL_NULL_V(p_class, Dictionary()); Dictionary class_api; - ERR_FAIL_NULL_V(p_class, class_api); - class_api["name"] = p_class->identifier != nullptr ? String(p_class->identifier->name) : String(); class_api["path"] = path; Array extends_class; diff --git a/modules/gdscript/language_server/gdscript_text_document.cpp b/modules/gdscript/language_server/gdscript_text_document.cpp index eaaa4bb2705..51315074faf 100644 --- a/modules/gdscript/language_server/gdscript_text_document.cpp +++ b/modules/gdscript/language_server/gdscript_text_document.cpp @@ -355,13 +355,11 @@ Dictionary GDScriptTextDocument::resolve(const Dictionary &p_params) { } Array GDScriptTextDocument::foldingRange(const Dictionary &p_params) { - Array arr; - return arr; + return Array(); } Array GDScriptTextDocument::codeLens(const Dictionary &p_params) { - Array arr; - return arr; + return Array(); } Array GDScriptTextDocument::documentLink(const Dictionary &p_params) { @@ -379,8 +377,7 @@ Array GDScriptTextDocument::documentLink(const Dictionary &p_params) { } Array GDScriptTextDocument::colorPresentation(const Dictionary &p_params) { - Array arr; - return arr; + return Array(); } Variant GDScriptTextDocument::hover(const Dictionary &p_params) { @@ -416,8 +413,7 @@ Array GDScriptTextDocument::definition(const Dictionary &p_params) { LSP::TextDocumentPositionParams params; params.load(p_params); List symbols; - Array arr = find_symbols(params, symbols); - return arr; + return find_symbols(params, symbols); } Variant GDScriptTextDocument::declaration(const Dictionary &p_params) { diff --git a/modules/gdscript/language_server/godot_lsp.h b/modules/gdscript/language_server/godot_lsp.h index 83a272de0e3..627b4486907 100644 --- a/modules/gdscript/language_server/godot_lsp.h +++ b/modules/gdscript/language_server/godot_lsp.h @@ -575,8 +575,7 @@ struct SaveOptions { */ struct ColorProviderOptions { Dictionary to_json() { - Dictionary dict; - return dict; + return Dictionary(); } }; @@ -585,8 +584,7 @@ struct ColorProviderOptions { */ struct FoldingRangeProviderOptions { Dictionary to_json() { - Dictionary dict; - return dict; + return Dictionary(); } }; diff --git a/modules/regex/regex.cpp b/modules/regex/regex.cpp index 544763f642e..3c6acfbc5b1 100644 --- a/modules/regex/regex.cpp +++ b/modules/regex/regex.cpp @@ -271,7 +271,7 @@ Ref RegEx::search(const String &p_subject, int p_offset, int p_end) } TypedArray RegEx::search_all(const String &p_subject, int p_offset, int p_end) const { - ERR_FAIL_COND_V_MSG(p_offset < 0, Array(), "RegEx search offset must be >= 0"); + ERR_FAIL_COND_V_MSG(p_offset < 0, TypedArray(), "RegEx search offset must be >= 0"); int last_end = 0; TypedArray result; diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index e6057ec2847..2bad4508cf1 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -571,23 +571,19 @@ void TileMap::set_pattern(int p_layer, const Vector2i &p_position, const Ref TileMap::terrain_fill_constraints(int p_layer, const Vector &p_to_replace, int p_terrain_set, const RBSet &p_constraints) { - HashMap err_value; - TILEMAP_CALL_FOR_LAYER_V(p_layer, err_value, terrain_fill_constraints, p_to_replace, p_terrain_set, p_constraints); + TILEMAP_CALL_FOR_LAYER_V(p_layer, (HashMap()), terrain_fill_constraints, p_to_replace, p_terrain_set, p_constraints); } HashMap TileMap::terrain_fill_connect(int p_layer, const Vector &p_coords_array, int p_terrain_set, int p_terrain, bool p_ignore_empty_terrains) { - HashMap err_value; - TILEMAP_CALL_FOR_LAYER_V(p_layer, err_value, terrain_fill_connect, p_coords_array, p_terrain_set, p_terrain, p_ignore_empty_terrains); + TILEMAP_CALL_FOR_LAYER_V(p_layer, (HashMap()), terrain_fill_connect, p_coords_array, p_terrain_set, p_terrain, p_ignore_empty_terrains); } HashMap TileMap::terrain_fill_path(int p_layer, const Vector &p_coords_array, int p_terrain_set, int p_terrain, bool p_ignore_empty_terrains) { - HashMap err_value; - TILEMAP_CALL_FOR_LAYER_V(p_layer, err_value, terrain_fill_path, p_coords_array, p_terrain_set, p_terrain, p_ignore_empty_terrains); + TILEMAP_CALL_FOR_LAYER_V(p_layer, (HashMap()), terrain_fill_path, p_coords_array, p_terrain_set, p_terrain, p_ignore_empty_terrains); } HashMap TileMap::terrain_fill_pattern(int p_layer, const Vector &p_coords_array, int p_terrain_set, TileSet::TerrainsPattern p_terrains_pattern, bool p_ignore_empty_terrains) { - HashMap err_value; - TILEMAP_CALL_FOR_LAYER_V(p_layer, err_value, terrain_fill_pattern, p_coords_array, p_terrain_set, p_terrains_pattern, p_ignore_empty_terrains); + TILEMAP_CALL_FOR_LAYER_V(p_layer, (HashMap()), terrain_fill_pattern, p_coords_array, p_terrain_set, p_terrains_pattern, p_ignore_empty_terrains); } void TileMap::set_cells_terrain_connect(int p_layer, TypedArray p_cells, int p_terrain_set, int p_terrain, bool p_ignore_empty_terrains) { diff --git a/scene/2d/tile_map_layer.cpp b/scene/2d/tile_map_layer.cpp index a427a092ebd..460daeb785e 100644 --- a/scene/2d/tile_map_layer.cpp +++ b/scene/2d/tile_map_layer.cpp @@ -2391,9 +2391,9 @@ HashMap TileMapLayer::terrain_fill_constrain } HashMap TileMapLayer::terrain_fill_connect(const Vector &p_coords_array, int p_terrain_set, int p_terrain, bool p_ignore_empty_terrains) const { + ERR_FAIL_COND_V(tile_set.is_null(), (HashMap())); + ERR_FAIL_INDEX_V(p_terrain_set, tile_set->get_terrain_sets_count(), (HashMap())); HashMap output; - ERR_FAIL_COND_V(tile_set.is_null(), output); - ERR_FAIL_INDEX_V(p_terrain_set, tile_set->get_terrain_sets_count(), output); // Build list and set of tiles that can be modified (painted and their surroundings). Vector can_modify_list; @@ -2491,14 +2491,13 @@ HashMap TileMapLayer::terrain_fill_connect(c } // Fill the terrains. - output = terrain_fill_constraints(can_modify_list, p_terrain_set, constraints); - return output; + return terrain_fill_constraints(can_modify_list, p_terrain_set, constraints); } HashMap TileMapLayer::terrain_fill_path(const Vector &p_coords_array, int p_terrain_set, int p_terrain, bool p_ignore_empty_terrains) const { + ERR_FAIL_COND_V(tile_set.is_null(), (HashMap())); + ERR_FAIL_INDEX_V(p_terrain_set, tile_set->get_terrain_sets_count(), (HashMap())); HashMap output; - ERR_FAIL_COND_V(tile_set.is_null(), output); - ERR_FAIL_INDEX_V(p_terrain_set, tile_set->get_terrain_sets_count(), output); // Make sure the path is correct and build the peering bit list while doing it. Vector neighbor_list; @@ -2564,14 +2563,13 @@ HashMap TileMapLayer::terrain_fill_path(cons } // Fill the terrains. - output = terrain_fill_constraints(can_modify_list, p_terrain_set, constraints); - return output; + return terrain_fill_constraints(can_modify_list, p_terrain_set, constraints); } HashMap TileMapLayer::terrain_fill_pattern(const Vector &p_coords_array, int p_terrain_set, TileSet::TerrainsPattern p_terrains_pattern, bool p_ignore_empty_terrains) const { + ERR_FAIL_COND_V(tile_set.is_null(), (HashMap())); + ERR_FAIL_INDEX_V(p_terrain_set, tile_set->get_terrain_sets_count(), (HashMap())); HashMap output; - ERR_FAIL_COND_V(tile_set.is_null(), output); - ERR_FAIL_INDEX_V(p_terrain_set, tile_set->get_terrain_sets_count(), output); // Build list and set of tiles that can be modified (painted and their surroundings). Vector can_modify_list; @@ -2616,8 +2614,7 @@ HashMap TileMapLayer::terrain_fill_pattern(c } // Fill the terrains. - output = terrain_fill_constraints(can_modify_list, p_terrain_set, constraints); - return output; + return terrain_fill_constraints(can_modify_list, p_terrain_set, constraints); } TileMapCell TileMapLayer::get_cell(const Vector2i &p_coords) const { @@ -3596,11 +3593,10 @@ TileMapLayer::~TileMapLayer() { } HashMap TerrainConstraint::get_overlapping_coords_and_peering_bits() const { + ERR_FAIL_COND_V(is_center_bit(), (HashMap())); + ERR_FAIL_COND_V(tile_set.is_null(), (HashMap())); HashMap output; - ERR_FAIL_COND_V(is_center_bit(), output); - ERR_FAIL_COND_V(tile_set.is_null(), output); - TileSet::TileShape shape = tile_set->get_tile_shape(); if (shape == TileSet::TILE_SHAPE_SQUARE) { switch (bit) { diff --git a/scene/main/resource_preloader.cpp b/scene/main/resource_preloader.cpp index 7cf24ffec39..946014bad9e 100644 --- a/scene/main/resource_preloader.cpp +++ b/scene/main/resource_preloader.cpp @@ -67,8 +67,7 @@ Array ResourcePreloader::_get_resources() const { i++; } - Array res = { names, arr }; - return res; + return Array{ names, arr }; } void ResourcePreloader::add_resource(const StringName &p_name, const Ref &p_resource) { diff --git a/scene/resources/2d/tile_set.cpp b/scene/resources/2d/tile_set.cpp index 71d74780a68..9d58958f858 100644 --- a/scene/resources/2d/tile_set.cpp +++ b/scene/resources/2d/tile_set.cpp @@ -1301,12 +1301,10 @@ Array TileSet::map_tile_proxy(int p_source_from, Vector2i p_coords_from, int p_a // Source matches. if (source_level_proxies.has(p_source_from)) { - Array output = { source_level_proxies[p_source_from], p_coords_from, p_alternative_from }; - return output; + return Array{ source_level_proxies[p_source_from], p_coords_from, p_alternative_from }; } - Array output = { p_source_from, p_coords_from, p_alternative_from }; - return output; + return Array{ p_source_from, p_coords_from, p_alternative_from }; } void TileSet::cleanup_invalid_tile_proxies() { diff --git a/servers/debugger/servers_debugger.cpp b/servers/debugger/servers_debugger.cpp index eba247cbe1f..f8dbde0eddc 100644 --- a/servers/debugger/servers_debugger.cpp +++ b/servers/debugger/servers_debugger.cpp @@ -73,8 +73,7 @@ bool ServersDebugger::ResourceUsage::deserialize(const Array &p_arr) { } Array ServersDebugger::ScriptFunctionSignature::serialize() { - Array arr = { name, id }; - return arr; + return Array{ name, id }; } bool ServersDebugger::ScriptFunctionSignature::deserialize(const Array &p_arr) {