[llvm] [ProfileData] Avoid repeated hash lookups (NFC) (PR #110789)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 1 21:24:59 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/110789

None

>From 64e30b47020122e636e38a9f0a4c29353832c3fc Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 1 Oct 2024 07:52:43 -0700
Subject: [PATCH] [ProfileData] Avoid repeated hash lookups (NFC)

---
 llvm/lib/ProfileData/MemProfReader.cpp | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/ProfileData/MemProfReader.cpp b/llvm/lib/ProfileData/MemProfReader.cpp
index 5e2d76e24dab7a..58622e5ed254ea 100644
--- a/llvm/lib/ProfileData/MemProfReader.cpp
+++ b/llvm/lib/ProfileData/MemProfReader.cpp
@@ -193,14 +193,10 @@ CallStackMap readStackInfo(const char *Ptr) {
 // addresses.
 bool mergeStackMap(const CallStackMap &From, CallStackMap &To) {
   for (const auto &[Id, Stack] : From) {
-    auto I = To.find(Id);
-    if (I == To.end()) {
-      To[Id] = Stack;
-    } else {
-      // Check that the PCs are the same (in order).
-      if (Stack != I->second)
-        return true;
-    }
+    auto [It, Inserted] = To.try_emplace(Id, Stack);
+    // Check that the PCs are the same (in order).
+    if (!Inserted && Stack != It->second)
+      return true;
   }
   return false;
 }



More information about the llvm-commits mailing list