Performance optimization

use try_emplace to avoid two lookups.
This commit is contained in:
2025-03-27 00:30:51 -04:00
parent 29bfd46843
commit 021ca575d1
2 changed files with 2 additions and 15 deletions

View File

@@ -213,9 +213,7 @@ bool ReArchive::OverwriteFile(const std::filesystem::path& archive, const std::f
auto value = file_entries.find(file_path);
if (value != file_entries.end())
target = &value->second;
if (!target)
return false;
@@ -264,12 +262,6 @@ std::vector<unsigned char> ReArchive::ReadFile(const std::filesystem::path& arch
auto header = GetHeader(buffer.data());
auto file_table = GetFileTable(header, in);
/*
for (const auto& e : file_table.GetEntries())
if (e.Path() == file_path)
target = &e;
*/
const FileEntry* target = nullptr;
auto file_entries = file_table.GetEntries();
@@ -277,8 +269,6 @@ for (const auto& e : file_table.GetEntries())
if (value != file_entries.end())
target = &value->second;
if (!target)
return {};

View File

@@ -4,10 +4,7 @@
using namespace ReArchive;
void FileTable::Append(const FileEntry& file_entry) {
if (entries.contains(file_entry.Path()))
return;
entries.insert(std::make_pair(file_entry.Path(), file_entry));
entries.try_emplace(file_entry.Path(), file_entry);
}
void FileTable::Remove(const FileEntry& file_entry) {