From 10bac1e829631f7c109bc76b047301cad67e9660 Mon Sep 17 00:00:00 2001 From: Binrui Dong Date: Thu, 30 Mar 2023 21:06:56 +0800 Subject: [PATCH] Avoid unnecessary copy construction [performance-unnecessary-copy-initialization] --- src/advanced_inv_pane.cpp | 2 +- src/construction.cpp | 2 +- src/consumption.cpp | 2 +- src/output.cpp | 2 +- src/sdltiles.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/advanced_inv_pane.cpp b/src/advanced_inv_pane.cpp index 4d8ab52ff9495..ed49465f8603f 100644 --- a/src/advanced_inv_pane.cpp +++ b/src/advanced_inv_pane.cpp @@ -60,7 +60,7 @@ void advanced_inventory_pane::load_settings( int saved_area_idx, !is_re_enter ) ? saved_area_idx : save_state->area_idx; const aim_location location = static_cast( i_location ); - const advanced_inv_area square = squares[location]; + const advanced_inv_area &square = squares[location]; // determine the square's vehicle/map item presence bool has_veh_items = square.can_store_in_vehicle() ? !square.veh->get_items( square.vstor ).empty() : false; diff --git a/src/construction.cpp b/src/construction.cpp index 8c9b4f7f5e186..8858987484241 100644 --- a/src/construction.cpp +++ b/src/construction.cpp @@ -1492,7 +1492,7 @@ void construct::done_appliance( const tripoint_bub_ms &p, Character & ) return; } - const item base = components.front(); + const item &base = components.front(); const vpart_id &vpart = vpart_appliance_from_item( base.typeId() ); // TODO: fix point types diff --git a/src/consumption.cpp b/src/consumption.cpp index 538a166cfa74c..6d8ef66694101 100644 --- a/src/consumption.cpp +++ b/src/consumption.cpp @@ -320,7 +320,7 @@ std::pair Character::compute_nutrient_range( our_extra_flags.insert( flag_COOKED ); } - const requirement_data requirements = rec.simple_requirements(); + const requirement_data &requirements = rec.simple_requirements(); const requirement_data::alter_item_comp_vector &component_requirements = requirements.get_components(); diff --git a/src/output.cpp b/src/output.cpp index 068b5409be808..6de513ccc75ea 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -295,7 +295,7 @@ std::string trim_by_length( const std::string &text, int width ) const std::vector color_segments = split_by_color( text ); for( size_t i = 0; i < color_segments.size() ; ++i ) { - std::string seg = color_segments[i]; + const std::string &seg = color_segments[i]; if( seg.empty() ) { // TODO: Check is required right now because, for a fully-color-tagged string, split_by_color // returns an empty string first diff --git a/src/sdltiles.cpp b/src/sdltiles.cpp index 11a276778ca01..8c3573e391283 100644 --- a/src/sdltiles.cpp +++ b/src/sdltiles.cpp @@ -768,7 +768,7 @@ std::string cata_tiles::get_omt_id_rotation_and_subtile( oter_id ot_id = oter_at( omp ); const oter_t &ot = *ot_id; oter_type_id ot_type_id = ot.get_type_id(); - oter_type_t ot_type = *ot_type_id; + const oter_type_t &ot_type = *ot_type_id; if( ot_type.has_connections() ) { // This would be for connected terrain