From e29f59a1024a049fc7727179ee47c7f611b4c410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 18 Jan 2024 20:04:29 +0100 Subject: [PATCH] GameInfoCache: Move some I/O out of the mutex. There's more to do. --- UI/GameInfoCache.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index 3e9ed1d496..44fdc88f38 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -340,16 +340,19 @@ static bool ReadFileToString(IFileSystem *fs, const char *filename, std::string if (handle < 0) { return false; } - if (mtx) { + std::string data; + data.resize(info.size); + fs->ReadFile(handle, (u8 *)data.data(), info.size); + fs->CloseFile(handle); + std::lock_guard lock(*mtx); - contents->resize(info.size); - fs->ReadFile(handle, (u8 *)contents->data(), info.size); + *contents = std::move(data); } else { contents->resize(info.size); fs->ReadFile(handle, (u8 *)contents->data(), info.size); + fs->CloseFile(handle); } - fs->CloseFile(handle); return true; } @@ -363,12 +366,13 @@ static bool ReadVFSToString(const char *filename, std::string *contents, std::mu } else { *contents = std::string((const char *)data, sz); } + } else { + return false; } delete [] data; - return data != nullptr; + return true; } - class GameInfoWorkItem : public Task { public: GameInfoWorkItem(const Path &gamePath, std::shared_ptr &info)