[llvm] [memprof] Avoid repeated map lookups (NFC) (PR #127027)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 13 00:06:47 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/127027.diff
1 Files Affected:
- (modified) llvm/lib/Analysis/MemoryProfileInfo.cpp (+3-3)
``````````diff
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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/127027
More information about the llvm-commits
mailing list