Skip to content

Commit bb35d06

Browse files
osjcnerzhul
authored andcommitted
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.
1 parent 007c844 commit bb35d06

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/content/subgames.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,19 @@ SubgameSpec findSubgame(const std::string &id)
6767
std::vector<GameFindPath> find_paths;
6868
while (!search_paths.at_end()) {
6969
std::string path = search_paths.next(PATH_DELIM);
70-
find_paths.emplace_back(path + DIR_DELIM + id, false);
71-
find_paths.emplace_back(path + DIR_DELIM + id + "_game", false);
70+
path.append(DIR_DELIM).append(id);
71+
find_paths.emplace_back(path, false);
72+
path.append("_game");
73+
find_paths.emplace_back(path, false);
7274
}
73-
find_paths.emplace_back(
74-
user + DIR_DELIM + "games" + DIR_DELIM + id + "_game", true);
75-
find_paths.emplace_back(user + DIR_DELIM + "games" + DIR_DELIM + id, true);
76-
find_paths.emplace_back(
77-
share + DIR_DELIM + "games" + DIR_DELIM + id + "_game", false);
78-
find_paths.emplace_back(share + DIR_DELIM + "games" + DIR_DELIM + id, false);
75+
76+
std::string game_base = DIR_DELIM;
77+
game_base = game_base.append("games").append(DIR_DELIM).append(id);
78+
std::string game_suffixed = game_base + "_game";
79+
find_paths.emplace_back(user + game_suffixed, true);
80+
find_paths.emplace_back(user + game_base, true);
81+
find_paths.emplace_back(share + game_suffixed, false);
82+
find_paths.emplace_back(share + game_base, false);
7983

8084
// Find game directory
8185
std::string game_path;

0 commit comments

Comments
 (0)