Skip to content

Commit af110e6

Browse files
kazutakahiratagithub-actions[bot]
authored andcommitted
Automerge: [ProfileData] Use DenseMap::try_emplace (NFC) (#140394)
We can simplify the code with structured binding and try_emplace. Note that try_emplace default-constructs the value if omitted. FWIW, structured binding, a C++17 feature, wasn't available in our codebase at the time the code was written.
2 parents bae8db6 + 2e2a792 commit af110e6

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

llvm/lib/ProfileData/InstrProfWriter.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,7 @@ void InstrProfWriter::overlapRecord(NamedInstrProfRecord &&Other,
178178
return;
179179
}
180180
auto &ProfileDataMap = It->second;
181-
bool NewFunc;
182-
ProfilingData::iterator Where;
183-
std::tie(Where, NewFunc) =
184-
ProfileDataMap.insert(std::make_pair(Hash, InstrProfRecord()));
181+
auto [Where, NewFunc] = ProfileDataMap.try_emplace(Hash);
185182
if (NewFunc) {
186183
Overlap.addOneMismatch(FuncLevelOverlap.Test);
187184
return;
@@ -200,10 +197,7 @@ void InstrProfWriter::addRecord(StringRef Name, uint64_t Hash,
200197
function_ref<void(Error)> Warn) {
201198
auto &ProfileDataMap = FunctionData[Name];
202199

203-
bool NewFunc;
204-
ProfilingData::iterator Where;
205-
std::tie(Where, NewFunc) =
206-
ProfileDataMap.insert(std::make_pair(Hash, InstrProfRecord()));
200+
auto [Where, NewFunc] = ProfileDataMap.try_emplace(Hash);
207201
InstrProfRecord &Dest = Where->second;
208202

209203
auto MapWarn = [&](instrprof_error E) {

0 commit comments

Comments
 (0)