Skip to content

Commit 5db95fd

Browse files
[memprof] Avoid repeated hash lookups (NFC) (#136268)
Note that we don't have to worry about CallstackProfileData[Id] default-constructing the value side of a new map entry. If that happens, AccessHistogramSize > 0 wouldn't be true, and the new map entry gets deleted right away.
1 parent a99c978 commit 5db95fd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

llvm/lib/ProfileData/MemProfReader.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,12 @@ Error RawMemProfReader::symbolizeAndFilterStackFrames(
600600
// Drop the entries where the callstack is empty.
601601
for (const uint64_t Id : EntriesToErase) {
602602
StackMap.erase(Id);
603-
if (CallstackProfileData[Id].AccessHistogramSize > 0)
604-
free((void *)CallstackProfileData[Id].AccessHistogram);
605-
CallstackProfileData.erase(Id);
603+
if (auto It = CallstackProfileData.find(Id);
604+
It != CallstackProfileData.end()) {
605+
if (It->second.AccessHistogramSize > 0)
606+
free((void *)It->second.AccessHistogram);
607+
CallstackProfileData.erase(It);
608+
}
606609
}
607610

608611
if (StackMap.empty())

0 commit comments

Comments
 (0)