From b7cec64fb2ad13a3c704cb37747dd05f32f047b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 13 Feb 2025 11:39:53 -0600 Subject: [PATCH] ZipFileReader: Small performance optimization when reading by filename --- Common/File/VFS/ZipFileReader.cpp | 8 ++++++-- GPU/Common/TextureReplacer.cpp | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Common/File/VFS/ZipFileReader.cpp b/Common/File/VFS/ZipFileReader.cpp index 8fd7c6d3e4..a3f85850b4 100644 --- a/Common/File/VFS/ZipFileReader.cpp +++ b/Common/File/VFS/ZipFileReader.cpp @@ -58,8 +58,12 @@ uint8_t *ZipFileReader::ReadFile(const char *path, size_t *size) { std::lock_guard guard(lock_); // Figure out the file size first. struct zip_stat zstat; - zip_stat(zip_file_, temp_path.c_str(), ZIP_FL_NOCASE | ZIP_FL_UNCHANGED, &zstat); - zip_file *file = zip_fopen(zip_file_, temp_path.c_str(), ZIP_FL_NOCASE | ZIP_FL_UNCHANGED); + int retval = zip_stat(zip_file_, temp_path.c_str(), ZIP_FL_NOCASE | ZIP_FL_UNCHANGED, &zstat); + if (retval != 0) { + ERROR_LOG(Log::IO, "Error opening %s from ZIP", temp_path.c_str()); + return 0; + } + zip_file *file = zip_fopen_index(zip_file_, zstat.index, ZIP_FL_NOCASE | ZIP_FL_UNCHANGED); if (!file) { ERROR_LOG(Log::IO, "Error opening %s from ZIP", temp_path.c_str()); return 0; diff --git a/GPU/Common/TextureReplacer.cpp b/GPU/Common/TextureReplacer.cpp index 0fd9cfb9f3..bd31cdda88 100644 --- a/GPU/Common/TextureReplacer.cpp +++ b/GPU/Common/TextureReplacer.cpp @@ -240,6 +240,7 @@ bool TextureReplacer::LoadIni(std::string *error) { void TextureReplacer::ScanForHashNamedFiles(VFSBackend *dir, std::map> &filenameMap) { // Scan the root of the texture folder/zip and preinitialize the hash map. + // TODO: Could put VFSFileReference into the map... std::vector filesInRoot; dir->GetFileListing("", &filesInRoot, nullptr); for (auto file : filesInRoot) {