Skip to content

Commit 69c7336

Browse files
[Analysis] Avoid repeated hash lookups (NFC) (llvm#129417)
1 parent 2c1e9f1 commit 69c7336

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

llvm/lib/Analysis/ProfileSummaryInfo.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,14 @@ std::optional<uint64_t>
141141
ProfileSummaryInfo::computeThreshold(int PercentileCutoff) const {
142142
if (!hasProfileSummary())
143143
return std::nullopt;
144-
auto iter = ThresholdCache.find(PercentileCutoff);
145-
if (iter != ThresholdCache.end()) {
146-
return iter->second;
147-
}
144+
auto [Iter, Inserted] = ThresholdCache.try_emplace(PercentileCutoff);
145+
if (!Inserted)
146+
return Iter->second;
148147
auto &DetailedSummary = Summary->getDetailedSummary();
149148
auto &Entry = ProfileSummaryBuilder::getEntryForPercentile(DetailedSummary,
150149
PercentileCutoff);
151150
uint64_t CountThreshold = Entry.MinCount;
152-
ThresholdCache[PercentileCutoff] = CountThreshold;
151+
Iter->second = CountThreshold;
153152
return CountThreshold;
154153
}
155154

0 commit comments

Comments
 (0)