impr: Improve file reading performance if opening of files is slow

This commit is contained in:
WerWolv 2023-03-21 09:47:42 +01:00
parent 0a0c0c0d07
commit 060ff56f9d
3 changed files with 12 additions and 10 deletions

@ -1 +1 @@
Subproject commit 213c0efc90a15a2034f744f64779bd097e5735a7
Subproject commit c24015b8f5b5e99bab18978a9d10f2e8c859f9b2

@ -1 +1 @@
Subproject commit 69a6330a6f0e557a1457aebfe671897954e6c6d9
Subproject commit 3599a304b368af608bd4da85a8853fa2f172d128

View File

@ -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) {