We don't like unnecessary heap allocations
This commit is contained in:
parent
d5c76f7cc5
commit
7d05b3f441
7 changed files with 34 additions and 34 deletions
|
@ -334,8 +334,7 @@ void engine_lua::do_parse_stage_from_config( ai_context &context, const config &
|
|||
return;
|
||||
}
|
||||
|
||||
stage_ptr st_ptr(new lua_stage_wrapper(context,cfg,*lua_ai_context_));
|
||||
if (st_ptr) {
|
||||
if(auto st_ptr = std::make_shared<lua_stage_wrapper>(context, cfg, *lua_ai_context_)) {
|
||||
st_ptr->on_create();
|
||||
*b = st_ptr;
|
||||
}
|
||||
|
|
|
@ -238,7 +238,7 @@ static hitrate_table_element tally(const statistics_t::stats::hitrate_map& by_ct
|
|||
unit_types.build_unit_type(defender_type, unit_type::BUILD_STATUS::FULL);
|
||||
|
||||
battle_context_unit_stats defender_bc(&defender_type, nullptr, false, nullptr, nullptr, 0 /* not used */);
|
||||
std::unique_ptr<combatant> current_defender(new combatant(defender_bc));
|
||||
auto current_defender = std::make_unique<combatant>(defender_bc);
|
||||
|
||||
for(const auto& i : by_cth) {
|
||||
int cth = i.first;
|
||||
|
|
|
@ -343,8 +343,8 @@ void playsingle_controller::hotkey_handler::load_autosave(const std::string& fil
|
|||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<config> res(new config(savegame.child_or_empty("snapshot")));
|
||||
std::shared_ptr<config> stats(new config(savegame.child_or_empty("statistics")));
|
||||
auto res = std::make_shared<config>(savegame.child_or_empty("snapshot"));
|
||||
auto stats = std::make_shared<config>(savegame.child_or_empty("statistics"));
|
||||
throw reset_gamestate_exception(res, stats, false);
|
||||
}
|
||||
|
||||
|
|
|
@ -1525,7 +1525,7 @@ bool preprocessor_data::get_chunk()
|
|||
std::size_t nb_arg = strings_.size() - token.stack_pos - 1;
|
||||
std::size_t optional_arg_num = 0;
|
||||
|
||||
std::unique_ptr<std::map<std::string, std::string>> defines{new std::map<std::string, std::string>};
|
||||
auto defines = std::make_unique<std::map<std::string, std::string>>();
|
||||
const std::string& dir = filesystem::directory_name(val.location.substr(0, val.location.find(' ')));
|
||||
|
||||
if(val.is_deprecated()) {
|
||||
|
@ -1577,7 +1577,7 @@ bool preprocessor_data::get_chunk()
|
|||
|
||||
filesystem::scoped_istream buffer{new std::istringstream(argument.second)};
|
||||
|
||||
std::unique_ptr<std::map<std::string, std::string>> temp_defines{new std::map<std::string, std::string>};
|
||||
auto temp_defines = std::make_unique<std::map<std::string, std::string>>();
|
||||
temp_defines->insert(defines->begin(), defines->end());
|
||||
|
||||
buf->add_preprocessor<preprocessor_data>(
|
||||
|
|
|
@ -50,9 +50,9 @@ BOOST_AUTO_TEST_CASE( test_insertion )
|
|||
std::shared_ptr<dummy_action> dact;
|
||||
|
||||
// Basic insertions
|
||||
std::shared_ptr<dummy_action> act1(new dummy_action(0, false, 1));
|
||||
std::shared_ptr<dummy_action> act2(new dummy_action(0, false, 2));
|
||||
std::shared_ptr<dummy_action> act3(new dummy_action(0, false, 3));
|
||||
auto act1 = std::make_shared<dummy_action>(0, false, 1);
|
||||
auto act2 = std::make_shared<dummy_action>(0, false, 2);
|
||||
auto act3 = std::make_shared<dummy_action>(0, false, 3);
|
||||
|
||||
sac.queue(0, act2);
|
||||
sac.queue(0, act3);
|
||||
|
@ -68,11 +68,11 @@ BOOST_AUTO_TEST_CASE( test_insertion )
|
|||
}
|
||||
|
||||
// Multi-turn insertions
|
||||
std::shared_ptr<dummy_action> act4(new dummy_action(0, false, 4));
|
||||
std::shared_ptr<dummy_action> act5(new dummy_action(0, false, 5));
|
||||
std::shared_ptr<dummy_action> act6(new dummy_action(0, false, 6));
|
||||
std::shared_ptr<dummy_action> act7(new dummy_action(0, false, 7));
|
||||
std::shared_ptr<dummy_action> act8(new dummy_action(0, false, 8));
|
||||
auto act4 = std::make_shared<dummy_action>(0, false, 4);
|
||||
auto act5 = std::make_shared<dummy_action>(0, false, 5);
|
||||
auto act6 = std::make_shared<dummy_action>(0, false, 6);
|
||||
auto act7 = std::make_shared<dummy_action>(0, false, 7);
|
||||
auto act8 = std::make_shared<dummy_action>(0, false, 8);
|
||||
sac.queue(1, act5);
|
||||
sac.queue(2, act8);
|
||||
sac.queue(1, act7);
|
||||
|
@ -103,12 +103,12 @@ BOOST_AUTO_TEST_CASE( test_removal )
|
|||
side_actions_container sac;
|
||||
std::shared_ptr<dummy_action> dact;
|
||||
|
||||
std::shared_ptr<dummy_action> act1(new dummy_action(0, false, 1));
|
||||
std::shared_ptr<dummy_action> act2(new dummy_action(0, false, 2));
|
||||
std::shared_ptr<dummy_action> act3(new dummy_action(0, false, 3));
|
||||
std::shared_ptr<dummy_action> act4(new dummy_action(0, false, 4));
|
||||
std::shared_ptr<dummy_action> act5(new dummy_action(0, false, 5));
|
||||
std::shared_ptr<dummy_action> act6(new dummy_action(0, false, 6));
|
||||
auto act1 = std::make_shared<dummy_action>(0, false, 1);
|
||||
auto act2 = std::make_shared<dummy_action>(0, false, 2);
|
||||
auto act3 = std::make_shared<dummy_action>(0, false, 3);
|
||||
auto act4 = std::make_shared<dummy_action>(0, false, 4);
|
||||
auto act5 = std::make_shared<dummy_action>(0, false, 5);
|
||||
auto act6 = std::make_shared<dummy_action>(0, false, 6);
|
||||
|
||||
sac.queue(0, act1);
|
||||
side_actions::iterator ite2 = sac.queue(0, act2);
|
||||
|
|
|
@ -707,7 +707,7 @@ void unit_filter_compound::fill(vconfig cfg)
|
|||
const wfl::unit_callable main(args.loc, args.u);
|
||||
wfl::map_formula_callable callable(main.fake_ptr());
|
||||
if (args.u2) {
|
||||
std::shared_ptr<wfl::unit_callable> secondary(new wfl::unit_callable(*args.u2));
|
||||
auto secondary = std::make_shared<wfl::unit_callable>(*args.u2);
|
||||
callable.add("other", wfl::variant(secondary));
|
||||
// It's not destroyed upon scope exit because the variant holds a reference
|
||||
}
|
||||
|
|
|
@ -62,19 +62,20 @@ action_ptr action::from_config(const config& cfg, bool hidden)
|
|||
std::string type = cfg["type"];
|
||||
|
||||
try {
|
||||
if(type=="move")
|
||||
return action_ptr(new move(cfg,hidden));
|
||||
else if(type=="attack")
|
||||
return action_ptr(new attack(cfg,hidden));
|
||||
else if(type=="recruit")
|
||||
return action_ptr(new recruit(cfg,hidden));
|
||||
else if(type=="recall")
|
||||
return action_ptr(new recall(cfg,hidden));
|
||||
else if(type=="suppose_dead")
|
||||
return action_ptr(new suppose_dead(cfg,hidden));
|
||||
} catch(const action::ctor_err&) {}
|
||||
if(type == "move")
|
||||
return std::make_shared<move>(cfg, hidden);
|
||||
else if(type == "attack")
|
||||
return std::make_shared<attack>(cfg, hidden);
|
||||
else if(type == "recruit")
|
||||
return std::make_shared<recruit>(cfg, hidden);
|
||||
else if(type == "recall")
|
||||
return std::make_shared<recall>(cfg, hidden);
|
||||
else if(type == "suppose_dead")
|
||||
return std::make_shared<suppose_dead>(cfg, hidden);
|
||||
} catch(const action::ctor_err&) {
|
||||
}
|
||||
|
||||
return action_ptr();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void action::hide()
|
||||
|
|
Loading…
Add table
Reference in a new issue