[llvm] 69c7336 - [Analysis] Avoid repeated hash lookups (NFC) (#129417)

via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 2 01:10:01 PST 2025


Author: Kazu Hirata
Date: 2025-03-02T01:09:58-08:00
New Revision: 69c7336c77f80b8f3417f2fb5143cbaa2fcb1c2a

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

LOG: [Analysis] Avoid repeated hash lookups (NFC) (#129417)

Added: 
    

Modified: 
    llvm/lib/Analysis/ProfileSummaryInfo.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ProfileSummaryInfo.cpp b/llvm/lib/Analysis/ProfileSummaryInfo.cpp
index fdad14571dfe4..1a6d2006202bc 100644
--- a/llvm/lib/Analysis/ProfileSummaryInfo.cpp
+++ b/llvm/lib/Analysis/ProfileSummaryInfo.cpp
@@ -141,15 +141,14 @@ std::optional<uint64_t>
 ProfileSummaryInfo::computeThreshold(int PercentileCutoff) const {
   if (!hasProfileSummary())
     return std::nullopt;
-  auto iter = ThresholdCache.find(PercentileCutoff);
-  if (iter != ThresholdCache.end()) {
-    return iter->second;
-  }
+  auto [Iter, Inserted] = ThresholdCache.try_emplace(PercentileCutoff);
+  if (!Inserted)
+    return Iter->second;
   auto &DetailedSummary = Summary->getDetailedSummary();
   auto &Entry = ProfileSummaryBuilder::getEntryForPercentile(DetailedSummary,
                                                              PercentileCutoff);
   uint64_t CountThreshold = Entry.MinCount;
-  ThresholdCache[PercentileCutoff] = CountThreshold;
+  Iter->second = CountThreshold;
   return CountThreshold;
 }
 


        


More information about the llvm-commits mailing list