diff --git a/llvm/include/llvm/ADT/MapVector.h b/llvm/include/llvm/ADT/MapVector.h index adbcda116dd56..015605fd98dff 100644 --- a/llvm/include/llvm/ADT/MapVector.h +++ b/llvm/include/llvm/ADT/MapVector.h @@ -99,8 +99,7 @@ class MapVector { } ValueT &operator[](const KeyT &Key) { - std::pair Pair = std::make_pair(Key, 0); - std::pair Result = Map.insert(Pair); + std::pair Result = Map.try_emplace(Key); auto &I = Result.first->second; if (Result.second) { Vector.push_back(std::make_pair(Key, ValueT())); @@ -119,7 +118,7 @@ class MapVector { template std::pair try_emplace(const KeyT &Key, Ts &&...Args) { - auto [It, Inserted] = Map.insert(std::make_pair(Key, 0)); + auto [It, Inserted] = Map.try_emplace(Key); if (Inserted) { It->second = Vector.size(); Vector.emplace_back(std::piecewise_construct, std::forward_as_tuple(Key), @@ -130,7 +129,7 @@ class MapVector { } template std::pair try_emplace(KeyT &&Key, Ts &&...Args) { - auto [It, Inserted] = Map.insert(std::make_pair(Key, 0)); + auto [It, Inserted] = Map.try_emplace(Key); if (Inserted) { It->second = Vector.size(); Vector.emplace_back(std::piecewise_construct, diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index f50d53eaaafca..5fb74a016a75e 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -3881,7 +3881,7 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU, if (!TypeUnitsUnderConstruction.empty() && AddrPool.hasBeenUsed()) return; - auto Ins = TypeSignatures.insert(std::make_pair(CTy, 0)); + auto Ins = TypeSignatures.try_emplace(CTy); if (!Ins.second) { CU.addDIETypeSignature(RefDie, Ins.first->second); return; diff --git a/llvm/lib/MC/StringTableBuilder.cpp b/llvm/lib/MC/StringTableBuilder.cpp index df316bae98cea..7accdc2a9e774 100644 --- a/llvm/lib/MC/StringTableBuilder.cpp +++ b/llvm/lib/MC/StringTableBuilder.cpp @@ -204,7 +204,7 @@ size_t StringTableBuilder::add(CachedHashStringRef S) { assert(S.size() > COFF::NameSize && "Short string in COFF string table!"); assert(!isFinalized()); - auto P = StringIndexMap.insert(std::make_pair(S, 0)); + auto P = StringIndexMap.try_emplace(S); if (P.second) { size_t Start = alignTo(Size, Alignment); P.first->second = Start; diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFixIrreducibleControlFlow.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFixIrreducibleControlFlow.cpp index 6c46673c36bf0..07171d472dc2d 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyFixIrreducibleControlFlow.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyFixIrreducibleControlFlow.cpp @@ -375,7 +375,7 @@ void WebAssemblyFixIrreducibleControlFlow::makeSingleEntryLoop( // add them as successors. DenseMap Indices; for (auto *Entry : SortedEntries) { - auto Pair = Indices.insert(std::make_pair(Entry, 0)); + auto Pair = Indices.try_emplace(Entry); assert(Pair.second); unsigned Index = MIB.getInstr()->getNumExplicitOperands() - 1;