[llvm] 2e2a792 - [ProfileData] Use DenseMap::try_emplace (NFC) (#140394)
via llvm-commits
llvm-commits at lists.llvm.org
Sat May 17 13:53:48 PDT 2025
Author: Kazu Hirata
Date: 2025-05-17T13:53:44-07:00
New Revision: 2e2a7923a428e78b5387be1e28f63db1bc1171bb
URL: https://github.com/llvm/llvm-project/commit/2e2a7923a428e78b5387be1e28f63db1bc1171bb
DIFF: https://github.com/llvm/llvm-project/commit/2e2a7923a428e78b5387be1e28f63db1bc1171bb.diff
LOG: [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.
Added:
Modified:
llvm/lib/ProfileData/InstrProfWriter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 9dc1a0d0b4678..39451c3d64870 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -178,10 +178,7 @@ void InstrProfWriter::overlapRecord(NamedInstrProfRecord &&Other,
return;
}
auto &ProfileDataMap = It->second;
- bool NewFunc;
- ProfilingData::iterator Where;
- std::tie(Where, NewFunc) =
- ProfileDataMap.insert(std::make_pair(Hash, InstrProfRecord()));
+ auto [Where, NewFunc] = ProfileDataMap.try_emplace(Hash);
if (NewFunc) {
Overlap.addOneMismatch(FuncLevelOverlap.Test);
return;
@@ -200,10 +197,7 @@ void InstrProfWriter::addRecord(StringRef Name, uint64_t Hash,
function_ref<void(Error)> Warn) {
auto &ProfileDataMap = FunctionData[Name];
- bool NewFunc;
- ProfilingData::iterator Where;
- std::tie(Where, NewFunc) =
- ProfileDataMap.insert(std::make_pair(Hash, InstrProfRecord()));
+ auto [Where, NewFunc] = ProfileDataMap.try_emplace(Hash);
InstrProfRecord &Dest = Where->second;
auto MapWarn = [&](instrprof_error E) {
More information about the llvm-commits
mailing list