Skip to content

Commit be51ef4

Browse files
[WebAssembly] Avoid repeated hash lookups (NFC) (#127960)
1 parent 4a8f414 commit be51ef4

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

llvm/lib/Target/WebAssembly/WebAssemblySortRegion.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ const SortRegion *SortRegionInfo::getRegionFor(const MachineBasicBlock *MBB) {
2828
// WE->contains(ML->getHeader()), but not ML->contains(WE->getHeader()).
2929
if ((ML && !WE) || (ML && WE && WE->contains(ML->getHeader()))) {
3030
// If the smallest region containing MBB is a loop
31-
if (LoopMap.count(ML))
32-
return LoopMap[ML].get();
33-
LoopMap[ML] = std::make_unique<ConcreteSortRegion<MachineLoop>>(ML);
34-
return LoopMap[ML].get();
31+
auto [It, Inserted] = LoopMap.try_emplace(ML);
32+
if (Inserted)
33+
It->second = std::make_unique<ConcreteSortRegion<MachineLoop>>(ML);
34+
return It->second.get();
3535
} else {
3636
// If the smallest region containing MBB is an exception
37-
if (ExceptionMap.count(WE))
38-
return ExceptionMap[WE].get();
39-
ExceptionMap[WE] =
40-
std::make_unique<ConcreteSortRegion<WebAssemblyException>>(WE);
41-
return ExceptionMap[WE].get();
37+
auto [It, Inserted] = ExceptionMap.try_emplace(WE);
38+
if (Inserted)
39+
It->second =
40+
std::make_unique<ConcreteSortRegion<WebAssemblyException>>(WE);
41+
return It->second.get();
4242
}
4343
}
4444

0 commit comments

Comments
 (0)