Skip to content

Commit

Permalink
Hide directories games should not know about from them.
Browse files Browse the repository at this point in the history
Stops some games from spending lots of time iterating over files they
should not care about. Helps the performance issues in #13847 quite a bit.
  • Loading branch information
hrydgard committed Sep 11, 2021
1 parent 46ada86 commit 04578ed
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion Core/HLE/sceIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <memory>

#include "Common/Thread/ThreadUtil.h"
#include "Common/TimeUtil.h"
#include "Common/Profiler/Profiler.h"

#include "Common/File/FileUtil.h"
Expand Down Expand Up @@ -2321,10 +2322,48 @@ static u32 sceIoDopen(const char *path) {
DirListing *dir = new DirListing();
SceUID id = kernelObjects.Create(dir);

double time = time_now_d();
dir->listing = pspFileSystem.GetDirListing(path);
dir->index = 0;
dir->name = std::string(path);

// Blacklist some directories that games should not be able to find out about.
// Speeds up directory iteration on slow Android Scoped Storage implementations :(
// Might also want to filter out PSP/GAME if not a homebrew, maybe also irrelevant directories
// in PSP/SAVEDATA, though iffy to know which ones are irrelevant..
if (!strcmp(path, "ms0:/PSP")) {
static const char *const pspFolderBlacklist[] = {
"CHEATS",
"PPSSPP_STATE",
"PLUGINS",
"SYSTEM",
"SCREENSHOT",
"TEXTURES",
"DUMP",
};
std::vector<PSPFileInfo> filtered;
for (const auto &entry : dir->listing) {
bool blacklisted = false;
for (auto black : pspFolderBlacklist) {
if (!strcasecmp(entry.name.c_str(), black)) {
blacklisted = true;
break;
}
}

if (!blacklisted) {
filtered.push_back(entry);
}
}

dir->listing = filtered;
}

double diff = time_now_d() - time;
//if (diff > 0.01) {
ERROR_LOG(IO, "sceIoDopen(%s) took %0.3f seconds", path, diff);
//}

// TODO: The result is delayed only from the memstick, it seems.
return id;
}
Expand All @@ -2349,7 +2388,7 @@ static u32 sceIoDread(int id, u32 dirent_addr) {
SceIoDirEnt *entry = (SceIoDirEnt*) Memory::GetPointer(dirent_addr);

if (dir->index == (int) dir->listing.size()) {
DEBUG_LOG(SCEIO, "sceIoDread( %d %08x ) - end of the line", id, dirent_addr);
DEBUG_LOG(SCEIO, "sceIoDread( %d %08x ) - end", id, dirent_addr);
entry->d_name[0] = '\0';
return 0;
}
Expand Down

0 comments on commit 04578ed

Please sign in to comment.