Avoid copying temp configs when adding config children (where possible)

A few of them are quite small, so this has no performance effect on those, but a few others
are potentially quite large, such as the one in campaign_server.cpp.
This commit is contained in:
Charles Dang 2017-12-03 07:37:12 +11:00
parent 583670ac2b
commit eab8380fc4
23 changed files with 35 additions and 35 deletions

View file

@ -76,7 +76,7 @@ void set_about(const config &cfg)
gather_images(about, images_default);
}
if(!misc.empty()) {
about_list.add_child("credits_group", misc);
about_list.add_child("credits_group", std::move(misc));
}
for(const config& campaign : cfg.child_range("campaign")) {
@ -95,7 +95,7 @@ void set_about(const config &cfg)
gather_images(about, images[id]);
}
about_list.add_child("credits_group", temp);
about_list.add_child("credits_group", std::move(temp));
}
}

View file

@ -173,7 +173,7 @@ bool addons_client::upload_addon(const std::string& id, std::string& response_me
}
config request_buf, response_buf;
request_buf.add_child("upload", cfg).add_child("data", addon_data);
request_buf.add_child("upload", cfg).add_child("data", std::move(addon_data));
LOG_ADDONS << "sending " << id << '\n';

View file

@ -314,7 +314,7 @@ void configuration::expand_simplified_aspects(side_number side, config &cfg) {
goal_config["value"] = criteria_config["value"];
criteria_config.remove_attribute("value");
}
parsed_config.add_child("goal", goal_config);
parsed_config.add_child("goal", std::move(goal_config));
continue;
}
// Now there's two possibilities. If the tag is [attacks] or contains either value= or [value],
@ -366,7 +366,7 @@ void configuration::expand_simplified_aspects(side_number side, config &cfg) {
base_config.add_child(child.key, child.cfg);
}
cfg.clear_children("ai");
cfg.add_child("ai", base_config);
cfg.add_child("ai", std::move(base_config));
}
} //end of namespace ai

View file

@ -1798,11 +1798,11 @@ recruitment_aspect::recruitment_aspect(readonly_context &context, const config &
// First, transform simplified tags into [recruit] tags.
for (config pattern : parsed_cfg.child_range("pattern")) {
parsed_cfg["pattern"] = true;
parsed_cfg.add_child("recruit", pattern);
parsed_cfg.add_child("recruit", std::move(pattern));
}
for (config total : parsed_cfg.child_range("total")) {
parsed_cfg["total"] = true;
parsed_cfg.add_child("recruit", total);
parsed_cfg.add_child("recruit", std::move(total));
}
parsed_cfg.clear_children("pattern", "total");
// Then, if there's no [recruit], add one.

View file

@ -560,7 +560,7 @@ void server::handle_request_campaign_list(const server::request& req)
}
config response;
response.add_child("campaigns", campaign_list);
response.add_child("campaigns", std::move(campaign_list));
std::ostringstream ostr;
write(ostr, response);

View file

@ -151,7 +151,7 @@ void chat_handler::send_whisper(const std::string& receiver, const std::string&
cwhisper["receiver"] = receiver;
cwhisper["message"] = message;
cwhisper["sender"] = preferences::login();
data.add_child("whisper", cwhisper);
data.add_child("whisper", std::move(cwhisper));
send_to_server(data);
}
@ -176,7 +176,7 @@ void chat_handler::send_chat_room_message(const std::string& room,
cmsg["room"] = room;
cmsg["message"] = message;
cmsg["sender"] = preferences::login();
data.add_child("message", cmsg);
data.add_child("message", std::move(cmsg));
send_to_server(data);
}

View file

@ -293,7 +293,7 @@ void connect_engine::update_and_send_diff(bool /*update_time_of_day*/)
config diff = level_.get_diff(old_level);
if(!diff.empty()) {
config scenario_diff;
scenario_diff.add_child("scenario_diff", diff);
scenario_diff.add_child("scenario_diff", std::move(diff));
send_to_server(scenario_diff);
}
}

View file

@ -78,7 +78,7 @@ manager::manager(const config& gamecfg, bool mp)
copy_keys(info, cfg, "era");
copy_keys(info, cfg, "modification");
depinfo_.add_child("modification", info);
depinfo_.add_child("modification", std::move(info));
}
}
@ -93,7 +93,7 @@ manager::manager(const config& gamecfg, bool mp)
copy_keys(info, cfg, "scenario");
copy_keys(info, cfg, "modification", true);
depinfo_.add_child("era", info);
depinfo_.add_child("era", std::move(info));
}
}
@ -106,7 +106,7 @@ manager::manager(const config& gamecfg, bool mp)
copy_keys(info, cfg, "era");
copy_keys(info, cfg, "modification", true);
depinfo_.add_child("scenario", info);
depinfo_.add_child("scenario", std::move(info));
}
}
@ -119,7 +119,7 @@ manager::manager(const config& gamecfg, bool mp)
copy_keys(info, cfg, "era");
copy_keys(info, cfg, "modification", true);
depinfo_.add_child("scenario", info);
depinfo_.add_child("scenario", std::move(info));
}
}

View file

@ -145,7 +145,7 @@ std::pair<wesnothd_connection_ptr, config> open_connection(std::string host)
config cfg;
config res;
cfg["version"] = game_config::version;
res.add_child("version", cfg);
res.add_child("version", std::move(cfg));
sock->send_data(res);
}

View file

@ -466,7 +466,7 @@ void addon_manager::load_addon_list(window& window)
addons_[id] = addon;
// Add the addon to the config entry
cfg_.add_child("campaign", pbl_cfg);
cfg_.add_child("campaign", std::move(pbl_cfg));
}
}

View file

@ -104,7 +104,7 @@ config generate_difficulty_config(const config& source)
temp["default"] = parsed.is_default();
temp["old_markup"] = true; // To prevent double parentheses in the dialog
result.add_child("difficulty", temp);
result.add_child("difficulty", std::move(temp));
}
}

View file

@ -328,7 +328,7 @@ void story_viewer::draw_floating_image(window& window, floating_image_list::cons
// TODO: implement handling of the tiling options.
//image["resize_mode"] = "tile_centered"
cfg.add_child("image", image);
cfg.add_child("image", std::move(image));
canvas& window_canvas = window.get_canvas(0);

View file

@ -491,7 +491,7 @@ void chatbox::close_window(size_t idx)
::config data, msg;
msg["room"] = t.name;
msg["player"] = preferences::login();
data.add_child("room_part", msg);
data.add_child("room_part", std::move(msg));
send_to_server(data);
}

View file

@ -1436,7 +1436,7 @@ void generate_contents()
config hidden_cfg = *help_config;
// Change the toplevel to our new, custom built one.
hidden_cfg.clear_children("toplevel");
hidden_cfg.add_child("toplevel", hidden_toplevel);
hidden_cfg.add_child("toplevel", std::move(hidden_toplevel));
hidden_sections = parse_config(&hidden_cfg);
}
catch (parse_error& e) {

View file

@ -83,7 +83,7 @@ void map_labels::write(config& res) const
config item;
label.second.write(item);
res.add_child("label", item);
res.add_child("label", std::move(item));
}
}
}

View file

@ -166,7 +166,7 @@ manager::~manager()
config cfg; // [line]
cfg["message"] = line;
history_id_cfg.add_child("line", cfg);
history_id_cfg.add_child("line", std::move(cfg));
}
history.add_child(history_id.first, history_id_cfg);

View file

@ -232,7 +232,7 @@ void replay::add_countdown_update(int value, int team)
config val;
val["value"] = value;
val["team"] = team;
cmd.add_child("countdown_update",val);
cmd.add_child("countdown_update", std::move(val));
}
void replay::add_synced_command(const std::string& name, const config& command)
{
@ -277,7 +277,7 @@ void replay::clear_labels(const std::string& team_name, bool force)
config val;
val["team_name"] = team_name;
val["force"] = force;
cmd.add_child("clear_labels",val);
cmd.add_child("clear_labels", std::move(val));
}
void replay::add_rename(const std::string& name, const map_location& loc)
@ -287,7 +287,7 @@ void replay::add_rename(const std::string& name, const map_location& loc)
config val;
loc.write(val);
val["name"] = name;
cmd.add_child("rename", val);
cmd.add_child("rename", std::move(val));
}

View file

@ -93,8 +93,8 @@ config replay_helper::get_attack(const map_location& a, const map_location& b,
a.write(src);
b.write(dst);
move.add_child("source",src);
move.add_child("destination",dst);
move.add_child("source", std::move(src));
move.add_child("destination", std::move(dst));
move["weapon"] = att_weapon;

View file

@ -263,7 +263,7 @@ config attack::to_config() const
config target_hex_cfg;
target_hex_cfg["x"]=target_hex_.wml_x();
target_hex_cfg["y"]=target_hex_.wml_y();
final_cfg.add_child("target_hex_",target_hex_cfg);
final_cfg.add_child("target_hex_", std::move(target_hex_cfg));
return final_cfg;
}

View file

@ -509,7 +509,7 @@ config move::to_config() const
config loc_cfg;
loc_cfg["x"]=loc.wml_x();
loc_cfg["y"]=loc.wml_y();
route_cfg.add_child("step",loc_cfg);
route_cfg.add_child("step", std::move(loc_cfg));
}
typedef std::pair<map_location,pathfind::marked_route::mark> pair_loc_mark;
for(pair_loc_mark const& item : route_->marks)
@ -521,9 +521,9 @@ config move::to_config() const
mark_cfg["zoc"]=item.second.zoc;
mark_cfg["capture"]=item.second.capture;
mark_cfg["invisible"]=item.second.invisible;
route_cfg.add_child("mark",mark_cfg);
route_cfg.add_child("mark", std::move(mark_cfg));
}
final_cfg.add_child("route_",route_cfg);
final_cfg.add_child("route_", std::move(route_cfg));
return final_cfg;
}

View file

@ -235,7 +235,7 @@ config recall::to_config() const
config loc_cfg;
loc_cfg["x"]=recall_hex_.wml_x();
loc_cfg["y"]=recall_hex_.wml_y();
final_cfg.add_child("recall_hex_",loc_cfg);
final_cfg.add_child("recall_hex_", std::move(loc_cfg));
return final_cfg;
}

View file

@ -214,7 +214,7 @@ config recruit::to_config() const
config loc_cfg;
loc_cfg["x"]=recruit_hex_.wml_x();
loc_cfg["y"]=recruit_hex_.wml_y();
final_cfg.add_child("recruit_hex_",loc_cfg);
final_cfg.add_child("recruit_hex_", std::move(loc_cfg));
return final_cfg;
}

View file

@ -182,7 +182,7 @@ config suppose_dead::to_config() const
config loc_cfg;
loc_cfg["x"]=loc_.wml_x();
loc_cfg["y"]=loc_.wml_y();
final_cfg.add_child("loc_",loc_cfg);
final_cfg.add_child("loc_", std::move(loc_cfg));
return final_cfg;
}