[llvm] abaa824 - [memprof] Avoid repeated hash lookups (NFC) (#110789)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 2 06:53:14 PDT 2024


Author: Kazu Hirata
Date: 2024-10-02T06:53:11-07:00
New Revision: abaa8247e86eb4fcb2cafcce320edc96855de611

URL: https://github.com/llvm/llvm-project/commit/abaa8247e86eb4fcb2cafcce320edc96855de611
DIFF: https://github.com/llvm/llvm-project/commit/abaa8247e86eb4fcb2cafcce320edc96855de611.diff

LOG: [memprof] Avoid repeated hash lookups (NFC) (#110789)

Added: 
    

Modified: 
    llvm/lib/ProfileData/MemProfReader.cpp

Removed: 
    


################################################################################
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