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; }