forked from ShuriZma/suyu
1
0
Fork 0

lm: Prevent redundant map lookups in Log()

We can perform the lookup and then do the contains check by checking the
end iterator. The benefit of this is that if we *do* find an entry, then
we aren't hashing into the map again to find it.

We can also get rid of an unused std::vector temporary while we're at
it.
This commit is contained in:
Lioncash 2021-04-23 09:24:19 -04:00
parent 6e2040c955
commit 5ba49f188b
1 changed files with 5 additions and 4 deletions

View File

@ -95,7 +95,7 @@ private:
std::memcpy(&header, data.data(), sizeof(LogPacketHeader));
offset += sizeof(LogPacketHeader);
LogPacketHeaderEntry entry{
const LogPacketHeaderEntry entry{
.pid = header.pid,
.tid = header.tid,
.severity = header.severity,
@ -107,14 +107,15 @@ private:
std::memcpy(tmp.data(), data.data() + offset, tmp.size());
entries[entry] = std::move(tmp);
} else {
const auto entry_iter = entries.find(entry);
// Append to existing entry
if (!entries.contains(entry)) {
if (entry_iter == entries.cend()) {
LOG_ERROR(Service_LM, "Log entry does not exist!");
return;
}
std::vector<u8> tmp(data.size() - sizeof(LogPacketHeader));
auto& existing_entry = entries[entry];
auto& existing_entry = entry_iter->second;
const auto base = existing_entry.size();
existing_entry.resize(base + (data.size() - sizeof(LogPacketHeader)));
std::memcpy(existing_entry.data() + base, data.data() + offset,