Skip to content

Commit

Permalink
Optimize filtered ListFiles() to only iterate once.
Browse files Browse the repository at this point in the history
  • Loading branch information
Malkierian committed Dec 8, 2024
1 parent 99d78d6 commit 3435b55
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/resource/archive/ArchiveManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,19 @@ bool ArchiveManager::HasFile(uint64_t hash) {
}

std::shared_ptr<std::vector<std::string>> ArchiveManager::ListFiles(const std::string& filter) {
auto list = ListFiles();
auto result = std::make_shared<std::vector<std::string>>();

std::copy_if(list->begin(), list->end(), std::back_inserter(*result),
[filter](const std::string& filePath) { return glob_match(filter.c_str(), filePath.c_str()); });

return result;
}

std::shared_ptr<std::vector<std::string>> ArchiveManager::ListFiles() {
auto list = std::make_shared<std::vector<std::string>>();
for (const auto& [hash, path] : mHashes) {
list->push_back(path);
if (filter != "" && glob_match(filter.c_str(), path.c_str()) || filter == "") {
list->push_back(path);
}
}
return list;
}

std::shared_ptr<std::vector<std::string>> ArchiveManager::ListFiles() {
return ListFiles("");
}

std::vector<uint32_t> ArchiveManager::GetGameVersions() {
return mGameVersions;
}
Expand Down

0 comments on commit 3435b55

Please sign in to comment.