[llvm] 9a59145 - [memprof] Avoid repeated map lookups (NFC) (#127027)

via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 13 09:12:08 PST 2025


Author: Kazu Hirata
Date: 2025-02-13T09:12:04-08:00
New Revision: 9a59145d8e3782196378102c42f70f575bc2f99a

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

LOG: [memprof] Avoid repeated map lookups (NFC) (#127027)

Added: 
    

Modified: 
    llvm/lib/Analysis/MemoryProfileInfo.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/MemoryProfileInfo.cpp b/llvm/lib/Analysis/MemoryProfileInfo.cpp
index a22344e19d045..913396f9ef5a2 100644
--- a/llvm/lib/Analysis/MemoryProfileInfo.cpp
+++ b/llvm/lib/Analysis/MemoryProfileInfo.cpp
@@ -164,8 +164,8 @@ void CallStackTrie::addCallStack(
     }
     // Update existing caller node if it exists.
     CallStackTrieNode *Prev = nullptr;
-    auto Next = Curr->Callers.find(StackId);
-    if (Next != Curr->Callers.end()) {
+    auto [Next, Inserted] = Curr->Callers.try_emplace(StackId);
+    if (!Inserted) {
       Prev = Curr;
       Curr = Next->second;
       Curr->addAllocType(AllocType);
@@ -177,7 +177,7 @@ void CallStackTrie::addCallStack(
     }
     // Otherwise add a new caller node.
     auto *New = new CallStackTrieNode(AllocType);
-    Curr->Callers[StackId] = New;
+    Next->second = New;
     Curr = New;
   }
   assert(Curr);


        


More information about the llvm-commits mailing list