Made use of T::emplace over T::insert where possible

This commit is contained in:
Charles Dang 2017-11-10 08:11:55 +11:00
parent 5d423ae66b
commit ecb72d5ec4
9 changed files with 14 additions and 16 deletions

View file

@ -312,8 +312,7 @@ void config_cache::add_define(const std::string& define)
if(config_cache_transaction::is_active()) {
// we have to add this to active map too
config_cache_transaction::instance().get_active_map(defines_map_).insert(
std::make_pair(define, preproc_define()));
config_cache_transaction::instance().get_active_map(defines_map_).emplace(define, preproc_define());
}
}

View file

@ -110,8 +110,7 @@ void display::add_overlay(const map_location& loc, const std::string& img, const
const halo::handle halo_handle = halo_man_->add(get_location_x(loc) + hex_size() / 2,
get_location_y(loc) + hex_size() / 2, halo, loc);
const overlay item(img, halo, halo_handle, team_name, item_id, visible_under_fog);
overlays_->insert(overlay_map::value_type(loc,item));
overlays_->emplace(loc, overlay(img, halo, halo_handle, team_name, item_id, visible_under_fog));
}
}

View file

@ -121,8 +121,8 @@ void editor_controller::init_tods(const config& game_config)
tods_map::iterator times = tods_.find(schedule_id);
if (times == tods_.end()) {
std::pair<tods_map::iterator, bool> new_times =
tods_.insert( std::pair<std::string, std::pair<std::string, std::vector<time_of_day> > >
(schedule_id, std::pair<std::string, std::vector<time_of_day> >(schedule_name, std::vector<time_of_day>())) );
tods_.emplace(schedule_id, std::make_pair(schedule_name, std::vector<time_of_day>()));
times = new_times.first;
} else {
ERR_ED << "Duplicate TOD Schedule identifiers." << std::endl;

View file

@ -194,7 +194,7 @@ void editor_map::invert_selection()
for (int x = -1; x < w() + 1; ++x) {
for (int y = -1; y < h() + 1; ++y) {
if (selection_.find(map_location(x, y)) == selection_.end()) {
new_selection.insert(map_location(x, y));
new_selection.emplace(x, y);
}
}
}

View file

@ -161,7 +161,7 @@ surface getMinimap(int w, int h, const gamemap &map, const team *vw, const std::
surf = scale_surface_sharp(tile, scale, scale);
i = normal_cache->insert(cache_map::value_type(terrain,surf)).first;
i = normal_cache->emplace(terrain, surf).first;
}
if (i != cache->end())
@ -170,12 +170,12 @@ surface getMinimap(int w, int h, const gamemap &map, const team *vw, const std::
if (need_fogging) {
surf = adjust_surface_color(surf, -50, -50, -50);
fog_cache->insert(cache_map::value_type(terrain, surf));
fog_cache->emplace(terrain, surf);
}
if (need_highlighting) {
surf = adjust_surface_color(surf, 50, 50, 50);
highlight_cache->insert(cache_map::value_type(terrain, surf));
highlight_cache->emplace(terrain, surf);
}
}

View file

@ -270,7 +270,7 @@ void class_tag::add_tag(const std::string &path, const class_tag &tag,
if ( path.empty() || path == "/" ){
tag_map::iterator it = tags_.find(tag.name_);
if (it == tags_.end()){
tags_.insert(tag_map_value(tag.name_,tag));
tags_.emplace(tag.name_, tag);
}else{
it->second.set_min(tag.min_);
it->second.set_max(tag.max_);
@ -294,7 +294,7 @@ void class_tag::add_tag(const std::string &path, const class_tag &tag,
class_tag subtag;
subtag.set_name(name);
subtag.add_tag(next_path,tag,root);
tags_.insert(tag_map_value(name,subtag));
tags_.emplace(name, subtag);
return;
}
it_tags->second.add_tag(next_path,tag,root);

View file

@ -226,10 +226,10 @@ public:
super_= s;
}
void add_key(const class_key& new_key){
keys_.insert(key_map_value(new_key.get_name(),new_key));
keys_.emplace(new_key.get_name(), new_key);
}
void add_tag(const class_tag& new_tag){
tags_.insert(tag_map_value(new_tag.name_,new_tag));
tags_.emplace(new_tag.name_, new_tag);
}
void add_link(const std::string & link);

View file

@ -699,7 +699,7 @@ static lg::log_domain log_server("server");
for (const config &bt : cfg.child_range("ban_time")) {
time_t duration = 0;
if (parse_time(bt["time"], &duration)) {
ban_times_.insert(default_ban_times::value_type(bt["name"], duration));
ban_times_.emplace(bt["name"], duration);
}
}
init_ban_help();

View file

@ -809,7 +809,7 @@ void server::send_password_request(socket_ptr socket, const std::string& msg,
void server::add_player(socket_ptr socket, const wesnothd::player& player)
{
bool inserted;
std::tie(std::ignore, inserted) = player_connections_.insert(player_connections::value_type(socket, player));
std::tie(std::ignore, inserted) = player_connections_.emplace(socket, player);
assert(inserted);
send_to_player(socket, games_and_users_list_);