[llvm] [ProfileData] Avoid repeated hash lookups (NFC) (PR #110789)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 1 21:25:32 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-pgo
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/110789.diff
1 Files Affected:
- (modified) llvm/lib/ProfileData/MemProfReader.cpp (+4-8)
``````````diff
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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/110789
More information about the llvm-commits
mailing list