diff --git a/Core/FileSystems/ISOFileSystem.cpp b/Core/FileSystems/ISOFileSystem.cpp index 2f31318241..d80b59c931 100644 --- a/Core/FileSystems/ISOFileSystem.cpp +++ b/Core/FileSystems/ISOFileSystem.cpp @@ -297,6 +297,11 @@ void ISOFileSystem::ReadDirectory(u32 startsector, u32 dirsize, TreeEntry *root, root->children.push_back(e); } } + + root->fastChildren.reserve(root->children.size()); + for (TreeEntry *e : root->children) { + root->fastChildren[e->name] = e; + } } ISOFileSystem::TreeEntry *ISOFileSystem::GetFromPath(std::string path, bool catchError) @@ -323,18 +328,12 @@ ISOFileSystem::TreeEntry *ISOFileSystem::GetFromPath(std::string path, bool catc if (path.length() > 0) { const std::string firstPathComponent = path.substr(0, path.find_first_of('/')); - for (size_t i = 0; i < e->children.size(); i++) - { - const std::string &n = e->children[i]->name; - - if (firstPathComponent == n) - { - //yay we got it - ne = e->children[i]; - name = n; - break; - } - } + auto child = e->fastChildren.find(firstPathComponent); + if (child != e->fastChildren.end()) { + //yay we got it + ne = child->second; + name = child->first; + } } if (ne) { diff --git a/Core/FileSystems/ISOFileSystem.h b/Core/FileSystems/ISOFileSystem.h index 5e46436ff1..82309bbd7e 100644 --- a/Core/FileSystems/ISOFileSystem.h +++ b/Core/FileSystems/ISOFileSystem.h @@ -19,6 +19,7 @@ #include #include +#include #include "FileSystem.h" @@ -68,7 +69,12 @@ private: bool isDirectory; TreeEntry *parent; - std::vector children; + + // slow lookup, in PSP-accurate sorting order + std::vector children; + + // fast lookup, in undefined order + std::unordered_map fastChildren; }; struct OpenFileEntry