diff --git a/.clang-tidy b/.clang-tidy index e4b6c9c5467d6..9b1f40408b7db 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -36,7 +36,6 @@ readability-*,\ -modernize-return-braced-init-list,\ -modernize-use-default-member-init,\ -modernize-use-emplace,\ --performance-inefficient-vector-operation,\ -performance-implicit-conversion-in-loop,\ -performance-inefficient-string-concatenation,\ -performance-type-promotion-in-math-fn,\ diff --git a/src/activity_item_handling.cpp b/src/activity_item_handling.cpp index 935ae8acbf1c2..2bb06f1a65d59 100644 --- a/src/activity_item_handling.cpp +++ b/src/activity_item_handling.cpp @@ -2526,6 +2526,7 @@ static requirement_check_result generic_multi_activity_check_requirement( player // come back here after successfully fetching your stuff if( act_prev.coords.empty() ) { std::vector local_src_set; + local_src_set.reserve( src_set.size() ); for( const tripoint &elem : src_set ) { local_src_set.push_back( here.getlocal( elem ) ); } diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 9b13ffba2d925..e276392fe44aa 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -3928,6 +3928,7 @@ std::vector cata_tiles::build_display_list() }; int numdisplays = SDL_GetNumVideoDisplays(); + display_names.reserve( numdisplays ); for( int i = 0 ; i < numdisplays ; i++ ) { display_names.emplace_back( std::to_string( i ), no_translation( SDL_GetDisplayName( i ) ) ); } diff --git a/src/debug_menu.cpp b/src/debug_menu.cpp index 1ef8722b50c4a..8233d04ddc03d 100644 --- a/src/debug_menu.cpp +++ b/src/debug_menu.cpp @@ -1956,6 +1956,7 @@ static void debug_menu_game_state() tripoint abs_sub = here.get_abs_sub(); std::string mfus; std::vector> sorted; + sorted.reserve( m_flag::MF_MAX ); for( int f = 0; f < m_flag::MF_MAX; f++ ) { sorted.push_back( {static_cast( f ), MonsterGenerator::generator().m_flag_usage_stats[f]} ); } @@ -1984,6 +1985,7 @@ static void debug_menu_game_state() if( !creature_counts.empty() ) { std::vector> creature_names_sorted; + creature_names_sorted.reserve( creature_counts.size() ); for( const std::pair &it : creature_counts ) { creature_names_sorted.emplace_back( it ); } diff --git a/src/faction_camp.cpp b/src/faction_camp.cpp index 36d21036c384a..816e23935347b 100644 --- a/src/faction_camp.cpp +++ b/src/faction_camp.cpp @@ -532,6 +532,7 @@ recipe_id base_camps::select_camp_option( const std::map std::vector pos_names; int choice = 0; + pos_names.reserve( pos_options.size() ); for( const auto &it : pos_options ) { pos_names.push_back( it.second.translated() ); } diff --git a/src/inventory.cpp b/src/inventory.cpp index 9673c463af1ca..98868d7e04331 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -449,6 +449,7 @@ void inventory::form_from_zone( map &m, std::unordered_set &zone_pts, bool assign_invlet ) { std::vector pts; + pts.reserve( zone_pts.size() ); for( const tripoint &elem : zone_pts ) { pts.push_back( m.getlocal( elem ) ); } diff --git a/src/item_contents.cpp b/src/item_contents.cpp index 23cd9a86aac0c..2c055e1cdef65 100644 --- a/src/item_contents.cpp +++ b/src/item_contents.cpp @@ -149,6 +149,7 @@ bool pocket_favorite_callback::key( const input_context &, const input_event &ev } std::vector itype_initializer; + itype_initializer.reserve( nearby_itypes.size() ); for( const std::pair &name : nearby_itypes ) { itype_initializer.emplace_back( name.first ); } diff --git a/src/magic_spell_effect.cpp b/src/magic_spell_effect.cpp index 43978f1c511db..20da42d70dd54 100644 --- a/src/magic_spell_effect.cpp +++ b/src/magic_spell_effect.cpp @@ -1229,6 +1229,7 @@ void spell_effect::dash( const spell &sp, Creature &caster, const tripoint &targ ::map &here = get_map(); // uses abs() coordinates std::vector trajectory; + trajectory.reserve( trajectory_local.size() ); for( const tripoint &local_point : trajectory_local ) { trajectory.push_back( here.getabs( local_point ) ); } diff --git a/src/mission_companion.cpp b/src/mission_companion.cpp index 030cc39ea8667..a74d805de20c2 100644 --- a/src/mission_companion.cpp +++ b/src/mission_companion.cpp @@ -2054,6 +2054,7 @@ npc_ptr talk_function::companion_choose_return( const tripoint_abs_omt &omt_pos, } std::vector npcs; + npcs.reserve( available.size() ); for( auto &elem : available ) { npcs.push_back( ( elem )->name ); } diff --git a/src/newcharacter.cpp b/src/newcharacter.cpp index 20adb1d839dde..d3ba67177b87c 100644 --- a/src/newcharacter.cpp +++ b/src/newcharacter.cpp @@ -1448,6 +1448,7 @@ tab_direction set_traits( avatar &u, points_left &points ) // Grab a list of the names of the bionics that block this trait // So that the player know what is preventing them from taking it std::vector conflict_names; + conflict_names.reserve( cbms_blocking_trait.size() ); for( const bionic_id &conflict : cbms_blocking_trait ) { conflict_names.emplace_back( conflict->name.translated() ); } diff --git a/src/npc.h b/src/npc.h index c931086cb9cc4..15f17794716a3 100644 --- a/src/npc.h +++ b/src/npc.h @@ -177,6 +177,7 @@ class job_data const std::pair &b ) { return a.second > b.second; } ); + ret.reserve( pairs.size() ); for( const std::pair &elem : pairs ) { ret.push_back( elem.first ); } diff --git a/src/requirements.cpp b/src/requirements.cpp index b60d8733beee0..b93d9293562b9 100644 --- a/src/requirements.cpp +++ b/src/requirements.cpp @@ -72,6 +72,7 @@ const requirement_data &string_id::obj() const std::vector requirement_data::get_all() { std::vector ret; + ret.reserve( requirements_all.size() ); for( const std::pair &pair : requirements_all ) { ret.push_back( pair.second ); } diff --git a/tests/encumbrance_test.cpp b/tests/encumbrance_test.cpp index bb495a9eb030b..61eec9fbab457 100644 --- a/tests/encumbrance_test.cpp +++ b/tests/encumbrance_test.cpp @@ -61,6 +61,7 @@ static void test_encumbrance( { CAPTURE( clothing_types ); std::vector clothing; + clothing.reserve( clothing_types.size() ); for( const std::string &type : clothing_types ) { clothing.push_back( item( type ) ); } diff --git a/tests/generic_factory_test.cpp b/tests/generic_factory_test.cpp index 0da6ab03c8d6b..711668efe3f6d 100644 --- a/tests/generic_factory_test.cpp +++ b/tests/generic_factory_test.cpp @@ -380,6 +380,7 @@ TEST_CASE( "string_and_int_ids_benchmark", "[.][generic_factory][int_id][string_ } const int test_flags_size = test_flags.size(); std::vector test_dyn_str_ids; + test_dyn_str_ids.reserve( test_flags.size() ); for( const auto &f : test_flags ) { test_dyn_str_ids.push_back( dyn_str_id( f.str() ) ); } diff --git a/tests/ranged_balance_test.cpp b/tests/ranged_balance_test.cpp index 40997377ae042..7d7b8b9bf838a 100644 --- a/tests/ranged_balance_test.cpp +++ b/tests/ranged_balance_test.cpp @@ -117,6 +117,7 @@ static std::vector firing_test( const dispersion_sources &dis const int range, const std::vector< Threshold > &thresholds ) { std::vector firing_stats; + firing_stats.reserve( thresholds.size() ); for( const Threshold &pear : thresholds ) { firing_stats.push_back( firing_test( dispersion, range, pear ) ); } diff --git a/tests/string_ids_test.cpp b/tests/string_ids_test.cpp index 24d06dfbd0e46..c3e7957968273 100644 --- a/tests/string_ids_test.cpp +++ b/tests/string_ids_test.cpp @@ -37,6 +37,7 @@ TEST_CASE( "string_ids_intern_test", "[string_id]" ) struct test_obj {}; std::vector> ids; // lots of ids to make sure that "interning" map gets expanded + ids.reserve( num_ids ); for( int i = 0; i < num_ids; ++i ) { ids.push_back( string_id( "test_id" + std::to_string( i ) ) ); } @@ -119,6 +120,7 @@ TEST_CASE( "string_id_sorting_test", "[string_id]" ) SECTION( "vector ids sorting" ) { std::vector vec; + vec.reserve( 10 ); for( int i = 0; i < 10; ++i ) { vec.push_back( id( "id" + std::to_string( i ) ) ); } @@ -150,6 +152,7 @@ TEST_CASE( "string_id_creation_benchmark", "[.][string_id][benchmark]" ) { static constexpr int num_test_strings = 30; std::vector test_strings; + test_strings.reserve( num_test_strings ); for( int i = 0; i < num_test_strings; ++i ) { test_strings.push_back( "some_test_string_" + std::to_string( i ) ); }