From 060ff56f9d103efd8599640b32bb846cdc7796ef Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 21 Mar 2023 09:47:42 +0100 Subject: [PATCH] impr: Improve file reading performance if opening of files is slow --- lib/external/libwolv | 2 +- lib/external/pattern_language | 2 +- .../source/content/providers/file_provider.cpp | 18 ++++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/external/libwolv b/lib/external/libwolv index 213c0efc9..c24015b8f 160000 --- a/lib/external/libwolv +++ b/lib/external/libwolv @@ -1 +1 @@ -Subproject commit 213c0efc90a15a2034f744f64779bd097e5735a7 +Subproject commit c24015b8f5b5e99bab18978a9d10f2e8c859f9b2 diff --git a/lib/external/pattern_language b/lib/external/pattern_language index 69a6330a6..3599a304b 160000 --- a/lib/external/pattern_language +++ b/lib/external/pattern_language @@ -1 +1 @@ -Subproject commit 69a6330a6f0e557a1457aebfe671897954e6c6d9 +Subproject commit 3599a304b368af608bd4da85a8853fa2f172d128 diff --git a/plugins/builtin/source/content/providers/file_provider.cpp b/plugins/builtin/source/content/providers/file_provider.cpp index 7b89e51f7..5c2542078 100644 --- a/plugins/builtin/source/content/providers/file_provider.cpp +++ b/plugins/builtin/source/content/providers/file_provider.cpp @@ -204,7 +204,9 @@ namespace hex::plugin::builtin { } this->m_fileStats = file.getFileInfo(); - this->m_sizeFile = wolv::io::File(this->m_path, wolv::io::File::Mode::Read); + this->m_sizeFile = file.clone(); + + this->m_files.emplace(std::this_thread::get_id(), std::move(file)); return true; } @@ -214,15 +216,15 @@ namespace hex::plugin::builtin { } wolv::io::File& FileProvider::getFile() { - std::scoped_lock lock(this->m_fileAccessMutex); - if (this->m_files.size() > 5) - this->m_files.clear(); + auto threadId = std::this_thread::get_id(); + if (!this->m_files.contains(threadId)) { + std::scoped_lock lock(this->m_fileAccessMutex); + if (!this->m_files.contains(threadId)) + this->m_files.emplace(threadId, this->m_sizeFile.clone()); + } - if (!this->m_files.contains(std::this_thread::get_id())) - this->m_files.emplace(std::this_thread::get_id(), wolv::io::File(this->m_path, wolv::io::File::Mode::Read)); - - return this->m_files[std::this_thread::get_id()]; + return this->m_files[threadId]; } void FileProvider::loadSettings(const nlohmann::json &settings) {