FileSystems: Change multiple internal functions to take std::string_view

This commit is contained in:
Henrik Rydgård
2026-02-06 12:10:24 +01:00
parent c85496c84d
commit f8077347e4
7 changed files with 24 additions and 33 deletions
+3 -6
View File
@@ -513,8 +513,7 @@ bool FixPathCase(const Path &realBasePath, std::string &path, FixPathCaseBehavio
if (len == 0)
return true;
if (path[len - 1] == '/')
{
if (path[len - 1] == '/') {
len--;
if (len == 0)
@@ -526,14 +525,12 @@ bool FixPathCase(const Path &realBasePath, std::string &path, FixPathCaseBehavio
fullPath.append(basePath);
size_t start = 0;
while (start < len)
{
while (start < len) {
size_t i = path.find('/', start);
if (i == std::string::npos)
i = len;
if (i > start)
{
if (i > start) {
std::string component = path.substr(start, i - start);
// Fix case and stop on nonexistant path component
+6 -6
View File
@@ -90,12 +90,12 @@ DirectoryFileSystem::~DirectoryFileSystem() {
// TODO(scoped): Merge the two below functions somehow.
Path DirectoryFileHandle::GetLocalPath(const Path &basePath, std::string localPath) const {
Path DirectoryFileHandle::GetLocalPath(const Path &basePath, std::string_view localPath) const {
if (localPath.empty())
return basePath;
if (localPath[0] == '/')
localPath.erase(0, 1);
localPath = localPath.substr(1);
if (fileSystemFlags_ & FileSystemFlags::STRIP_PSP) {
if (localPath == "PSP") {
@@ -108,12 +108,12 @@ Path DirectoryFileHandle::GetLocalPath(const Path &basePath, std::string localPa
return basePath / localPath;
}
Path DirectoryFileSystem::GetLocalPath(std::string internalPath) const {
Path DirectoryFileSystem::GetLocalPath(std::string_view internalPath) const {
if (internalPath.empty())
return basePath;
if (internalPath[0] == '/')
internalPath.erase(0, 1);
internalPath = internalPath.substr(1);
if (flags & FileSystemFlags::STRIP_PSP) {
if (internalPath == "PSP") {
@@ -1053,8 +1053,8 @@ VFSFileSystem::~VFSFileSystem() {
entries.clear();
}
std::string VFSFileSystem::GetLocalPath(const std::string &localPath) const {
return basePath + localPath;
std::string VFSFileSystem::GetLocalPath(std::string_view localPath) const {
return join(basePath, localPath);
}
bool VFSFileSystem::MkDir(const std::string &dirname) {
+3 -3
View File
@@ -51,7 +51,7 @@ struct DirectoryFileHandle {
DirectoryFileHandle(Flags flags, FileSystemFlags fileSystemFlags)
: replay_(flags != SKIP_REPLAY), fileSystemFlags_(fileSystemFlags) {}
Path GetLocalPath(const Path &basePath, std::string localpath) const;
Path GetLocalPath(const Path &basePath, std::string_view localPath) const;
bool Open(const Path &basePath, std::string &fileName, FileAccess access, u32 &err);
size_t Read(u8* pointer, s64 size);
size_t Write(const u8* pointer, s64 size);
@@ -104,7 +104,7 @@ private:
IHandleAllocator *hAlloc;
FileSystemFlags flags;
Path GetLocalPath(std::string internalPath) const;
Path GetLocalPath(std::string_view internalPath) const;
};
// VFSFileSystem: Ability to map in Android APK paths as well! Does not support all features, only meant for fonts.
@@ -151,5 +151,5 @@ private:
std::string basePath;
IHandleAllocator *hAlloc;
std::string GetLocalPath(const std::string &localpath) const;
std::string GetLocalPath(std::string_view localpath) const;
};
+8 -7
View File
@@ -255,7 +255,7 @@ void ISOFileSystem::ReadDirectory(TreeEntry *root) const {
root->valid = true;
}
const ISOFileSystem::TreeEntry *ISOFileSystem::GetFromPath(const std::string &path, bool catchError) {
const ISOFileSystem::TreeEntry *ISOFileSystem::GetFromPath(std::string_view path, bool catchError) {
const size_t pathLength = path.length();
if (pathLength == 0) {
@@ -288,9 +288,9 @@ const ISOFileSystem::TreeEntry *ISOFileSystem::GetFromPath(const std::string &pa
if (nextSlashIndex == std::string::npos)
nextSlashIndex = pathLength;
const std::string firstPathComponent = path.substr(pathIndex, nextSlashIndex - pathIndex);
const std::string_view firstPathComponent = path.substr(pathIndex, nextSlashIndex - pathIndex);
for (size_t i = 0; i < entry->children.size(); i++) {
const std::string &n = entry->children[i]->name;
const std::string_view n = entry->children[i]->name;
if (firstPathComponent == n) {
//yay we got it
nextEntry = entry->children[i];
@@ -302,8 +302,9 @@ const ISOFileSystem::TreeEntry *ISOFileSystem::GetFromPath(const std::string &pa
if (nextEntry) {
entry = nextEntry;
if (!entry->valid)
if (!entry->valid) {
ReadDirectory(entry);
}
pathIndex += name.length();
if (pathIndex < pathLength && path[pathIndex] == '/')
++pathIndex;
@@ -311,9 +312,9 @@ const ISOFileSystem::TreeEntry *ISOFileSystem::GetFromPath(const std::string &pa
if (pathLength <= pathIndex)
return entry;
} else {
if (catchError)
ERROR_LOG(Log::FileSystem, "File '%s' not found", path.c_str());
if (catchError) {
ERROR_LOG(Log::FileSystem, "File '%.*s' not found", STR_VIEW(path));
}
return 0;
}
}
+1 -1
View File
@@ -98,7 +98,7 @@ private:
TreeEntry entireISO;
void ReadDirectory(TreeEntry *root) const;
const TreeEntry *GetFromPath(const std::string &path, bool catchError = true);
const TreeEntry *GetFromPath(std::string_view path, bool catchError = true);
std::string EntryFullPath(const TreeEntry *e);
};
+2 -9
View File
@@ -236,19 +236,12 @@ void VirtualDiscFileSystem::DoState(PointerWrap &p)
// We don't savestate handlers (loaded on fs load), but if they change, it may not load properly.
}
Path VirtualDiscFileSystem::GetLocalPath(std::string localpath) const {
Path VirtualDiscFileSystem::GetLocalPath(std::string_view localpath) const {
if (localpath.empty())
return basePath;
if (localpath[0] == '/')
localpath.erase(0,1);
//Convert slashes
#ifdef _WIN32
for (size_t i = 0; i < localpath.size(); i++) {
if (localpath[i] == '/')
localpath[i] = '\\';
}
#endif
localpath.remove_prefix(1);
return basePath / localpath;
}
+1 -1
View File
@@ -64,7 +64,7 @@ private:
// Warning: modifies input string.
int getFileListIndex(std::string &fileName);
int getFileListIndex(u32 accessBlock, u32 accessSize, bool blockMode = false) const;
Path GetLocalPath(std::string localpath) const;
Path GetLocalPath(std::string_view localpath) const;
typedef void *HandlerLibrary;
typedef int HandlerHandle;