Skip to content

Commit

Permalink
perf: use emplace_back
Browse files Browse the repository at this point in the history
  • Loading branch information
scarf005 committed Oct 8, 2023
1 parent 2586412 commit 0d48dd8
Show file tree
Hide file tree
Showing 80 changed files with 985 additions and 985 deletions.
6 changes: 3 additions & 3 deletions src/active_item_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ void active_item_cache::add( item &it )
return;
}
if( it.can_revive() ) {
special_items[ special_item_type::corpse ].push_back( it );
special_items[ special_item_type::corpse ].emplace_back( it );
}
if( it.get_use( "explosion" ) ) {
special_items[ special_item_type::explosive ].push_back( it );
special_items[ special_item_type::explosive ].emplace_back( it );
}
target_list.push_back( it );
target_list.emplace_back( it );
}

bool active_item_cache::empty() const
Expand Down
2 changes: 1 addition & 1 deletion src/activity_actor_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class move_items_activity_actor : public activity_actor
relative_destination( relative_destination ) {

for( item *&it : items ) {
target_items.push_back( it );
target_items.emplace_back( it );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4469,7 +4469,7 @@ void activity_handlers::fertilize_plot_do_turn( player_activity *act, player *p
auto check_fertilizer = [&]( bool ask_user = true ) -> void {
if( act->str_values.empty() )
{
act->str_values.push_back( "" );
act->str_values.emplace_back( "" );
}
fertilizer = itype_id( act->str_values[0] );

Expand Down
66 changes: 33 additions & 33 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,13 +796,13 @@ void wash_activity_actor::finish( player_activity &act, Character &who )
}

std::vector<item_comp> comps;
comps.push_back( item_comp( itype_water, required.water ) );
comps.push_back( item_comp( itype_water_clean, required.water ) );
comps.emplace_back( itype_water, required.water );
comps.emplace_back( itype_water_clean, required.water );
who.as_player()->consume_items( comps, 1, is_liquid_crafting_component );

std::vector<item_comp> comps1;
comps1.push_back( item_comp( itype_soap, required.cleanser ) );
comps1.push_back( item_comp( itype_detergent, required.cleanser ) );
comps1.emplace_back( itype_soap, required.cleanser );
comps1.emplace_back( itype_detergent, required.cleanser );
who.as_player()->consume_items( comps1 );

who.add_msg_if_player( m_good, _( "You washed your items." ) );
Expand Down Expand Up @@ -976,7 +976,7 @@ static bool vehicle_activity( player &p, const tripoint &src_loc, int vpindex, c
// values[7]
p.activity->values.push_back( here.getabs( src_loc ).z );
// this would only be used for refilling tasks
p.activity->targets.emplace_back( safe_reference<item>() );
p.activity->targets.emplace_back( );
p.activity->placement = here.getabs( src_loc );
p.activity_vehicle_part_index = -1;
return true;
Expand Down Expand Up @@ -1736,7 +1736,7 @@ static std::vector<std::tuple<tripoint, itype_id, int>> requirements_map( player
continue;
}
}
requirement_map.push_back( std::make_tuple( point_elem, map_elem.first, map_elem.second ) );
requirement_map.emplace_back( point_elem, map_elem.first, map_elem.second );
}
}
// Ok we now have a list of all the items that match the requirements, their points, and a quantity for each one.
Expand All @@ -1760,8 +1760,8 @@ static std::vector<std::tuple<tripoint, itype_id, int>> requirements_map( player
}
if( item_quantity >= quantity_required ) {
// it's just this spot that can fulfil the requirement on its own
final_map.push_back( std::make_tuple( pos_here, item_here, std::min<int>( quantity_here,
quantity_required ) ) );
final_map.emplace_back( pos_here, item_here, std::min<int>( quantity_here,
quantity_required ) );
if( quantity_here >= quantity_required ) {
line_found = true;
break;
Expand All @@ -1787,10 +1787,10 @@ static std::vector<std::tuple<tripoint, itype_id, int>> requirements_map( player
int quantity_here2 = std::get<2>( *it );
if( comp_elem.type == item_here2 ) {
if( quantity_here2 >= remainder ) {
final_map.push_back( std::make_tuple( pos_here2, item_here2, remainder ) );
final_map.emplace_back( pos_here2, item_here2, remainder );
line_found = true;
} else {
final_map.push_back( std::make_tuple( pos_here2, item_here2, remainder ) );
final_map.emplace_back( pos_here2, item_here2, remainder );
remainder -= quantity_here2;
}
}
Expand Down Expand Up @@ -1818,8 +1818,8 @@ static std::vector<std::tuple<tripoint, itype_id, int>> requirements_map( player
}
if( item_quantity >= quantity_required ) {
// it's just this spot that can fulfil the requirement on its own
final_map.push_back( std::make_tuple( pos_here, item_here, std::min<int>( quantity_here,
quantity_required ) ) );
final_map.emplace_back( pos_here, item_here, std::min<int>( quantity_here,
quantity_required ) );
if( quantity_here >= quantity_required ) {
line_found = true;
break;
Expand All @@ -1845,10 +1845,10 @@ static std::vector<std::tuple<tripoint, itype_id, int>> requirements_map( player
int quantity_here2 = std::get<2>( *it );
if( comp_elem.type == item_here2 ) {
if( quantity_here2 >= remainder ) {
final_map.push_back( std::make_tuple( pos_here2, item_here2, remainder ) );
final_map.emplace_back( pos_here2, item_here2, remainder );
line_found = true;
} else {
final_map.push_back( std::make_tuple( pos_here2, item_here2, remainder ) );
final_map.emplace_back( pos_here2, item_here2, remainder );
remainder -= quantity_here2;
}
}
Expand All @@ -1872,7 +1872,7 @@ static std::vector<std::tuple<tripoint, itype_id, int>> requirements_map( player
item &test_item = *item::spawn_temporary( item_here, calendar::start_of_cataclysm );
if( test_item.has_quality( tool_qual, qual_level ) ) {
// it's just this spot that can fulfil the requirement on its own
final_map.push_back( std::make_tuple( pos_here, item_here, 1 ) );
final_map.emplace_back( pos_here, item_here, 1 );
line_found = true;
break;
}
Expand Down Expand Up @@ -1920,7 +1920,7 @@ static bool construction_activity( player &p, const zone_data * /*zone*/, const
for( const std::vector<tool_comp> &it : built_chosen.requirements->get_tools() ) {
p.consume_tools( it );
}
p.backlog.push_front( std::make_unique<player_activity>( activity_to_restore ) );
p.backlog.emplace_front( std::make_unique<player_activity>( activity_to_restore ) );
p.assign_activity( ACT_BUILD );
p.activity->placement = here.getabs( src_loc );
return true;
Expand Down Expand Up @@ -2249,7 +2249,7 @@ void activity_on_turn_move_loot( player_activity &act, player &p )
continue;
}
it->set_owner( p );
items.push_back( std::make_pair( it, true ) );
items.emplace_back( it, true );
}
} else {
src_veh = nullptr;
Expand All @@ -2260,7 +2260,7 @@ void activity_on_turn_move_loot( player_activity &act, player &p )
continue;
}
it->set_owner( p );
items.push_back( std::make_pair( it, false ) );
items.emplace_back( it, false );
}

//Skip items that have already been processed
Expand Down Expand Up @@ -2387,7 +2387,7 @@ static bool mine_activity( player &p, const tripoint &src_loc )
moves /= 2;
}
p.assign_activity( powered ? ACT_JACKHAMMER : ACT_PICKAXE, moves );
p.activity->targets.push_back( chosen_item );
p.activity->targets.emplace_back( chosen_item );
p.activity->placement = here.getabs( src_loc );
return true;

Expand All @@ -2407,12 +2407,12 @@ static bool chop_tree_activity( player &p, const tripoint &src_loc )
const ter_id ter = here.ter( src_loc );
if( here.has_flag( flag_TREE, src_loc ) ) {
p.assign_activity( ACT_CHOP_TREE, moves, -1, p.get_item_position( best_qual ) );
p.activity->targets.push_back( best_qual );
p.activity->targets.emplace_back( best_qual );
p.activity->placement = here.getabs( src_loc );
return true;
} else if( ter == t_trunk || ter == t_stump ) {
p.assign_activity( ACT_CHOP_LOGS, moves, -1, p.get_item_position( best_qual ) );
p.activity->targets.push_back( best_qual );
p.activity->targets.emplace_back( best_qual );
p.activity->placement = here.getabs( src_loc );
return true;
}
Expand Down Expand Up @@ -2751,7 +2751,7 @@ static requirement_check_result generic_multi_activity_check_requirement( player
return SKIP_LOCATION;
} else {
if( !check_only ) {
p.backlog.push_front( std::make_unique<player_activity>( act_id ) );
p.backlog.emplace_front( std::make_unique<player_activity>( act_id ) );
p.assign_activity( ACT_FETCH_REQUIRED );
player_activity &act_prev = *p.backlog.front();
act_prev.str_values.push_back( what_we_need.str() );
Expand Down Expand Up @@ -2810,7 +2810,7 @@ static bool generic_multi_activity_do( player &p, const activity_id &act_id,
} else if( reason == do_activity_reason::NEEDS_TILLING && here.has_flag( flag_PLOWABLE, src_loc ) &&
p.has_quality( qual_DIG, 1 ) && !here.has_furn( src_loc ) ) {
p.assign_activity( ACT_CHURN, 18000, -1 );
p.backlog.push_front( std::make_unique<player_activity>( act_id ) );
p.backlog.emplace_front( std::make_unique<player_activity>( act_id ) );
p.activity->placement = src;
return false;
} else if( reason == do_activity_reason::NEEDS_PLANTING &&
Expand All @@ -2829,24 +2829,24 @@ static bool generic_multi_activity_do( player &p, const activity_id &act_id,
continue;
}
iexamine::plant_seed( p, src_loc, itype_id( seed ) );
p.backlog.push_front( std::make_unique<player_activity>( act_id ) );
p.backlog.emplace_front( std::make_unique<player_activity>( act_id ) );
return false;
}
} else if( reason == do_activity_reason::NEEDS_CHOPPING && p.has_quality( qual_AXE, 1 ) ) {
if( chop_plank_activity( p, src_loc ) ) {
p.backlog.push_front( std::make_unique<player_activity>( act_id ) );
p.backlog.emplace_front( std::make_unique<player_activity>( act_id ) );
return false;
}
} else if( reason == do_activity_reason::NEEDS_BUTCHERING ||
reason == do_activity_reason::NEEDS_BIG_BUTCHERING ) {
if( butcher_corpse_activity( p, src_loc, reason ) ) {
p.backlog.push_front( std::make_unique<player_activity>( act_id ) );
p.backlog.emplace_front( std::make_unique<player_activity>( act_id ) );
return false;
}
} else if( reason == do_activity_reason::CAN_DO_CONSTRUCTION ||
reason == do_activity_reason::CAN_DO_PREREQ ) {
if( here.partial_con_at( src_loc ) ) {
p.backlog.push_front( std::make_unique<player_activity>( act_id ) );
p.backlog.emplace_front( std::make_unique<player_activity>( act_id ) );
p.assign_activity( std::make_unique<player_activity>( ACT_BUILD ) );
p.activity->placement = src;
return false;
Expand All @@ -2869,34 +2869,34 @@ static bool generic_multi_activity_do( player &p, const activity_id &act_id,
}
} else if( reason == do_activity_reason::NEEDS_TREE_CHOPPING && p.has_quality( qual_AXE, 1 ) ) {
if( chop_tree_activity( p, src_loc ) ) {
p.backlog.push_front( std::make_unique<player_activity>( act_id ) );
p.backlog.emplace_front( std::make_unique<player_activity>( act_id ) );
return false;
}
} else if( reason == do_activity_reason::NEEDS_FISHING && p.has_quality( qual_FISHING, 1 ) ) {
p.backlog.push_front( std::make_unique<player_activity>( act_id ) );
p.backlog.emplace_front( std::make_unique<player_activity>( act_id ) );
// we don't want to keep repeating the fishing activity, just piggybacking on this functions structure to find requirements.
p.activity = std::make_unique<player_activity>();
item *best_rod = p.best_quality_item( qual_FISHING );
p.assign_activity( std::make_unique<player_activity>( ACT_FISH, to_moves<int>( 5_hours ), 0,
0, best_rod->tname() ) );
p.activity->targets.push_back( best_rod );
p.activity->targets.emplace_back( best_rod );
p.activity->coord_set = g->get_fishable_locations( ACTIVITY_SEARCH_DISTANCE, src_loc );
return false;
} else if( reason == do_activity_reason::NEEDS_MINING ) {
// if have enough batteries to continue etc.
p.backlog.push_front( std::make_unique<player_activity>( act_id ) );
p.backlog.emplace_front( std::make_unique<player_activity>( act_id ) );
if( mine_activity( p, src_loc ) ) {
return false;
}
} else if( reason == do_activity_reason::NEEDS_VEH_DECONST ) {
if( vehicle_activity( p, src_loc, p.activity_vehicle_part_index, 'o' ) ) {
p.backlog.push_front( std::make_unique<player_activity>( act_id ) );
p.backlog.emplace_front( std::make_unique<player_activity>( act_id ) );
return false;
}
p.activity_vehicle_part_index = -1;
} else if( reason == do_activity_reason::NEEDS_VEH_REPAIR ) {
if( vehicle_activity( p, src_loc, p.activity_vehicle_part_index, 'r' ) ) {
p.backlog.push_front( std::make_unique<player_activity>( act_id ) );
p.backlog.emplace_front( std::make_unique<player_activity>( act_id ) );
return false;
}
p.activity_vehicle_part_index = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/advanced_inv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ void advanced_inventory::recalc_pane( side p )
categories.insert( it.cat );
}
for( auto &cat : categories ) {
pane.items.push_back( advanced_inv_listitem( cat ) );
pane.items.emplace_back( cat );
}
}
// Finally sort all items (category headers will now be moved to their proper position)
Expand Down
26 changes: 13 additions & 13 deletions src/armor_layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,43 +328,43 @@ std::vector<std::string> clothing_flags_description( const item &worn_item )
std::vector<std::string> description_stack;

if( worn_item.has_flag( flag_FIT ) ) {
description_stack.push_back( _( "It fits you well." ) );
description_stack.emplace_back( _( "It fits you well." ) );
} else if( worn_item.has_flag( flag_VARSIZE ) ) {
description_stack.push_back( _( "It could be refitted." ) );
description_stack.emplace_back( _( "It could be refitted." ) );
}

if( worn_item.has_flag( flag_HOOD ) ) {
description_stack.push_back( _( "It has a hood." ) );
description_stack.emplace_back( _( "It has a hood." ) );
}
if( worn_item.has_flag( flag_POCKETS ) ) {
description_stack.push_back( _( "It has pockets." ) );
description_stack.emplace_back( _( "It has pockets." ) );
}
if( worn_item.has_flag( flag_WATERPROOF ) ) {
description_stack.push_back( _( "It is waterproof." ) );
description_stack.emplace_back( _( "It is waterproof." ) );
}
if( worn_item.has_flag( flag_WATER_FRIENDLY ) ) {
description_stack.push_back( _( "It is water friendly." ) );
description_stack.emplace_back( _( "It is water friendly." ) );
}
if( worn_item.has_flag( flag_FANCY ) ) {
description_stack.push_back( _( "It looks fancy." ) );
description_stack.emplace_back( _( "It looks fancy." ) );
}
if( worn_item.has_flag( flag_SUPER_FANCY ) ) {
description_stack.push_back( _( "It looks really fancy." ) );
description_stack.emplace_back( _( "It looks really fancy." ) );
}
if( worn_item.has_flag( flag_FLOTATION ) ) {
description_stack.push_back( _( "You will not drown today." ) );
description_stack.emplace_back( _( "You will not drown today." ) );
}
if( worn_item.has_flag( flag_OVERSIZE ) ) {
description_stack.push_back( _( "It is very bulky." ) );
description_stack.emplace_back( _( "It is very bulky." ) );
}
if( worn_item.has_flag( flag_SWIM_GOGGLES ) ) {
description_stack.push_back( _( "It helps you to see clearly underwater." ) );
description_stack.emplace_back( _( "It helps you to see clearly underwater." ) );
}
if( worn_item.has_flag( flag_SEMITANGIBLE ) ) {
description_stack.push_back( _( "It can occupy the same space as other things." ) );
description_stack.emplace_back( _( "It can occupy the same space as other things." ) );
}
if( worn_item.has_flag( flag_COMPACT ) ) {
description_stack.push_back( _( "It won't encumber you when worn with other things." ) );
description_stack.emplace_back( _( "It won't encumber you when worn with other things." ) );
}

return description_stack;
Expand Down
14 changes: 7 additions & 7 deletions src/artifact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ itype_id new_natural_artifact( artifact_natural_property prop )

def.sym = ":";
def.color = c_yellow;
def.materials.push_back( material_id( "stone" ) );
def.materials.emplace_back( "stone" );
def.volume = rng( shape_data.volume_min, shape_data.volume_max );
def.weight = rng( shape_data.weight_min, shape_data.weight_max );
def.melee[DT_BASH] = 0;
Expand Down Expand Up @@ -1121,16 +1121,16 @@ void it_artifact_tool::deserialize( const JsonObject &jo )
// quite some time. Loading and saving once will write things out as a JSON
// array.
if( jo.has_string( "m1" ) ) {
materials.push_back( material_id( jo.get_string( "m1" ) ) );
materials.emplace_back( jo.get_string( "m1" ) );
}
if( jo.has_string( "m2" ) ) {
materials.push_back( material_id( jo.get_string( "m2" ) ) );
materials.emplace_back( jo.get_string( "m2" ) );
}
// Assumption, perhaps dangerous, that we won't wind up with m1 and m2 and
// a materials array in our serialized objects at the same time.
if( jo.has_array( "materials" ) ) {
for( const std::string id : jo.get_array( "materials" ) ) {
materials.push_back( material_id( id ) );
materials.emplace_back( id );
}
}
volume = jo.get_int( "volume" ) * units::legacy_volume_factor;
Expand Down Expand Up @@ -1230,16 +1230,16 @@ void it_artifact_armor::deserialize( const JsonObject &jo )
// quite some time. Loading and saving once will write things out as a JSON
// array.
if( jo.has_string( "m1" ) ) {
materials.push_back( material_id( jo.get_string( "m1" ) ) );
materials.emplace_back( jo.get_string( "m1" ) );
}
if( jo.has_string( "m2" ) ) {
materials.push_back( material_id( jo.get_string( "m2" ) ) );
materials.emplace_back( jo.get_string( "m2" ) );
}
// Assumption, perhaps dangerous, that we won't wind up with m1 and m2 and
// a materials array in our serialized objects at the same time.
if( jo.has_array( "materials" ) ) {
for( const std::string id : jo.get_array( "materials" ) ) {
materials.push_back( material_id( id ) );
materials.emplace_back( id );
}
}
volume = jo.get_int( "volume" ) * units::legacy_volume_factor;
Expand Down
Loading

0 comments on commit 0d48dd8

Please sign in to comment.