summaryrefslogtreecommitdiff
path: root/src/content
diff options
context:
space:
mode:
authorJozef Behran <jozuejozef@gmail.com>2019-03-07 02:20:33 -0500
committerLoïc Blot <nerzhul@users.noreply.github.com>2019-03-07 08:20:33 +0100
commitbb35d062255ed74f6e1ebe0f7c4714054803b248 (patch)
tree5bb33f4cdfb68f5854df2398da5f55dbf0ecb7a0 /src/content
parent007c8440d7da324af05631389f9a850e805fb3b3 (diff)
downloadminetest-bb35d062255ed74f6e1ebe0f7c4714054803b248.tar.gz
minetest-bb35d062255ed74f6e1ebe0f7c4714054803b248.tar.bz2
minetest-bb35d062255ed74f6e1ebe0f7c4714054803b248.zip
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.
Diffstat (limited to 'src/content')
-rw-r--r--src/content/subgames.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/content/subgames.cpp b/src/content/subgames.cpp
index 4b0e37f7c..39cdc056f 100644
--- a/src/content/subgames.cpp
+++ b/src/content/subgames.cpp
@@ -67,15 +67,19 @@ SubgameSpec findSubgame(const std::string &id)
std::vector<GameFindPath> find_paths;
while (!search_paths.at_end()) {
std::string path = search_paths.next(PATH_DELIM);
- find_paths.emplace_back(path + DIR_DELIM + id, false);
- find_paths.emplace_back(path + DIR_DELIM + id + "_game", false);
+ path.append(DIR_DELIM).append(id);
+ 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);
- find_paths.emplace_back(user + DIR_DELIM + "games" + DIR_DELIM + id, true);
- find_paths.emplace_back(
- share + DIR_DELIM + "games" + DIR_DELIM + id + "_game", false);
- find_paths.emplace_back(share + DIR_DELIM + "games" + DIR_DELIM + id, false);
+
+ std::string game_base = DIR_DELIM;
+ game_base = game_base.append("games").append(DIR_DELIM).append(id);
+ std::string game_suffixed = game_base + "_game";
+ find_paths.emplace_back(user + game_suffixed, true);
+ 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
std::string game_path;