Skip to content

Commit

Permalink
Config: optimized merge_children and merge_children_by_attribute
Browse files Browse the repository at this point in the history
This should mean a performance boost when the game config manager processes [units] tags.
Since they're all merged into one, it's very likely whole addon's worth of unit type configs
were being copied (twice)! Worth noting that a lot of addons use the tag amendment syntax
([+units]), but it's unlikely that meant no copying was done at all.
  • Loading branch information
Vultraz committed Feb 21, 2018
1 parent 35d9b30 commit 7b4f980
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/config.cpp
Expand Up @@ -329,12 +329,12 @@ void config::merge_children(const std::string& key)
}

config merged_children;
for(const config& cfg : child_range(key)) {
merged_children.append(cfg);
for(config& cfg : child_range(key)) {
merged_children.append(std::move(cfg));
}

clear_children_impl(key);
add_child(key, merged_children);
add_child(key, std::move(merged_children));
}

void config::merge_children_by_attribute(const std::string& key, const std::string& attribute)
Expand All @@ -347,13 +347,13 @@ void config::merge_children_by_attribute(const std::string& key, const std::stri

typedef std::map<std::string, config> config_map;
config_map merged_children_map;
for(const config& cfg : child_range(key)) {
merged_children_map[cfg[attribute]].append(cfg);
for(config& cfg : child_range(key)) {
merged_children_map[cfg[attribute]].append(std::move(cfg));
}

clear_children_impl(key);
for(const config_map::value_type& i : merged_children_map) {
add_child(key, i.second);
add_child(key, i.second); // TODO: can we use std::move?
}
}

Expand Down

0 comments on commit 7b4f980

Please sign in to comment.