From 6e2040c9551422307920a708773e0099222470a6 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 23 Apr 2021 09:20:52 -0400 Subject: [PATCH 1/3] lm: Resolve -Wextra-semi warning Resolves a trivial warning with clang. --- src/core/hle/service/lm/lm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/service/lm/lm.cpp b/src/core/hle/service/lm/lm.cpp index 7d7542fc2..70f5272af 100644 --- a/src/core/hle/service/lm/lm.cpp +++ b/src/core/hle/service/lm/lm.cpp @@ -46,7 +46,7 @@ struct hash { boost::hash_combine(seed, k.severity); boost::hash_combine(seed, k.verbosity); return seed; - }; + } }; } // namespace std From 5ba49f188bf39cdfc71a6b78d7d846b4b0725dc3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 23 Apr 2021 09:24:19 -0400 Subject: [PATCH 2/3] 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. --- src/core/hle/service/lm/lm.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/hle/service/lm/lm.cpp b/src/core/hle/service/lm/lm.cpp index 70f5272af..b311ad300 100644 --- a/src/core/hle/service/lm/lm.cpp +++ b/src/core/hle/service/lm/lm.cpp @@ -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 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, From 29cd40bded0ee7885fdef9f0a2fbb4e6ad297561 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 23 Apr 2021 09:27:15 -0400 Subject: [PATCH 3/3] lm: Make use of insert_or_assign() in Log() Avoids unnecessary default construction of an entry in cases where no entry exists before overwriting the created entry. --- src/core/hle/service/lm/lm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/service/lm/lm.cpp b/src/core/hle/service/lm/lm.cpp index b311ad300..9bcf8870d 100644 --- a/src/core/hle/service/lm/lm.cpp +++ b/src/core/hle/service/lm/lm.cpp @@ -105,7 +105,7 @@ private: if (True(header.flags & LogPacketFlags::Head)) { std::vector tmp(data.size() - sizeof(LogPacketHeader)); std::memcpy(tmp.data(), data.data() + offset, tmp.size()); - entries[entry] = std::move(tmp); + entries.insert_or_assign(entry, std::move(tmp)); } else { const auto entry_iter = entries.find(entry);