From 99451af85d7a4d160550194195b5ebbd5d250940 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sat, 1 Mar 2025 08:21:39 -0800 Subject: [PATCH] [Analysis] Avoid repeated hash lookups (NFC) --- llvm/lib/Analysis/ProfileSummaryInfo.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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 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; }