[llvm] [memprof] Avoid repeated map lookups (NFC) (PR #127027)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 13 00:06:13 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/127027
None
>From 60fd8ec73d9e15f120f2329146d092387eb498df Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 12 Feb 2025 08:58:26 -0800
Subject: [PATCH] [memprof] Avoid repeated map lookups (NFC)
---
llvm/lib/Analysis/MemoryProfileInfo.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
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