forked from Mirrorlandia_minetest/minetest
Optimize string handling in path search (#8098)
Use "append" method to construct the various game paths instead of wasteful string concatenation. Additionally, use a temporary to extract and reuse a result of a few common subexpressions to further reduce the overhead.
This commit is contained in:
parent
007c8440d7
commit
bb35d06225
@ -67,15 +67,19 @@ SubgameSpec findSubgame(const std::string &id)
|
|||||||
std::vector<GameFindPath> find_paths;
|
std::vector<GameFindPath> find_paths;
|
||||||
while (!search_paths.at_end()) {
|
while (!search_paths.at_end()) {
|
||||||
std::string path = search_paths.next(PATH_DELIM);
|
std::string path = search_paths.next(PATH_DELIM);
|
||||||
find_paths.emplace_back(path + DIR_DELIM + id, false);
|
path.append(DIR_DELIM).append(id);
|
||||||
find_paths.emplace_back(path + DIR_DELIM + id + "_game", false);
|
find_paths.emplace_back(path, false);
|
||||||
|
path.append("_game");
|
||||||
|
find_paths.emplace_back(path, false);
|
||||||
}
|
}
|
||||||
find_paths.emplace_back(
|
|
||||||
user + DIR_DELIM + "games" + DIR_DELIM + id + "_game", true);
|
std::string game_base = DIR_DELIM;
|
||||||
find_paths.emplace_back(user + DIR_DELIM + "games" + DIR_DELIM + id, true);
|
game_base = game_base.append("games").append(DIR_DELIM).append(id);
|
||||||
find_paths.emplace_back(
|
std::string game_suffixed = game_base + "_game";
|
||||||
share + DIR_DELIM + "games" + DIR_DELIM + id + "_game", false);
|
find_paths.emplace_back(user + game_suffixed, true);
|
||||||
find_paths.emplace_back(share + DIR_DELIM + "games" + DIR_DELIM + id, false);
|
find_paths.emplace_back(user + game_base, true);
|
||||||
|
find_paths.emplace_back(share + game_suffixed, false);
|
||||||
|
find_paths.emplace_back(share + game_base, false);
|
||||||
|
|
||||||
// Find game directory
|
// Find game directory
|
||||||
std::string game_path;
|
std::string game_path;
|
||||||
|
Loading…
Reference in New Issue
Block a user