core: Reduce string copies in GetGameFileFromPath()
Eliminates some minor string churn where applicable. Also eliminates an unnecessary vector copy.
This commit is contained in:
parent
322349e8cc
commit
9d3d0ae999
|
@ -92,33 +92,43 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
|
||||||
std::string dir_name;
|
std::string dir_name;
|
||||||
std::string filename;
|
std::string filename;
|
||||||
Common::SplitPath(path, &dir_name, &filename, nullptr);
|
Common::SplitPath(path, &dir_name, &filename, nullptr);
|
||||||
|
|
||||||
if (filename == "00") {
|
if (filename == "00") {
|
||||||
const auto dir = vfs->OpenDirectory(dir_name, FileSys::Mode::Read);
|
const auto dir = vfs->OpenDirectory(dir_name, FileSys::Mode::Read);
|
||||||
std::vector<FileSys::VirtualFile> concat;
|
std::vector<FileSys::VirtualFile> concat;
|
||||||
for (u8 i = 0; i < 0x10; ++i) {
|
|
||||||
auto next = dir->GetFile(fmt::format("{:02X}", i));
|
for (u32 i = 0; i < 0x10; ++i) {
|
||||||
if (next != nullptr)
|
const auto file_name = fmt::format("{:02X}", i);
|
||||||
|
auto next = dir->GetFile(file_name);
|
||||||
|
|
||||||
|
if (next != nullptr) {
|
||||||
concat.push_back(std::move(next));
|
concat.push_back(std::move(next));
|
||||||
else {
|
} else {
|
||||||
next = dir->GetFile(fmt::format("{:02x}", i));
|
next = dir->GetFile(file_name);
|
||||||
if (next != nullptr)
|
|
||||||
concat.push_back(std::move(next));
|
if (next == nullptr) {
|
||||||
else
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
concat.push_back(std::move(next));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (concat.empty())
|
if (concat.empty()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return FileSys::ConcatenatedVfsFile::MakeConcatenatedFile(concat, dir->GetName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Common::FS::IsDirectory(path))
|
return FileSys::ConcatenatedVfsFile::MakeConcatenatedFile(std::move(concat),
|
||||||
return vfs->OpenFile(path + "/" + "main", FileSys::Mode::Read);
|
dir->GetName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Common::FS::IsDirectory(path)) {
|
||||||
|
return vfs->OpenFile(path + "/main", FileSys::Mode::Read);
|
||||||
|
}
|
||||||
|
|
||||||
return vfs->OpenFile(path, FileSys::Mode::Read);
|
return vfs->OpenFile(path, FileSys::Mode::Read);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct System::Impl {
|
struct System::Impl {
|
||||||
explicit Impl(System& system)
|
explicit Impl(System& system)
|
||||||
: kernel{system}, fs_controller{system}, memory{system},
|
: kernel{system}, fs_controller{system}, memory{system},
|
||||||
|
|
Reference in New Issue