mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Add an unordered_map to TreeEntry for faster lookup
This commit is contained in:
parent
481eac7184
commit
3f36b476ad
2 changed files with 18 additions and 13 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "FileSystem.h"
|
||||
|
||||
|
@ -68,7 +69,12 @@ private:
|
|||
bool isDirectory;
|
||||
|
||||
TreeEntry *parent;
|
||||
std::vector<TreeEntry*> children;
|
||||
|
||||
// slow lookup, in PSP-accurate sorting order
|
||||
std::vector<TreeEntry *> children;
|
||||
|
||||
// fast lookup, in undefined order
|
||||
std::unordered_map<std::string, TreeEntry *> fastChildren;
|
||||
};
|
||||
|
||||
struct OpenFileEntry
|
||||
|
|
Loading…
Add table
Reference in a new issue