diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index cda1276497b51..dc92acafb25d2 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -619,16 +619,16 @@ MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type, Buffer.append(LinkedToSym->getName()); support::endian::write(Buffer, UniqueID, endianness::native); StringRef UniqueMapKey = StringRef(Buffer); - EntryNewPair = ELFUniquingMap.insert(std::make_pair(UniqueMapKey, nullptr)); + EntryNewPair = ELFUniquingMap.try_emplace(UniqueMapKey); } else if (!Section.isSingleStringRef()) { SmallString<128> Buffer; StringRef UniqueMapKey = Section.toStringRef(Buffer); SectionLen = UniqueMapKey.size(); - EntryNewPair = ELFUniquingMap.insert(std::make_pair(UniqueMapKey, nullptr)); + EntryNewPair = ELFUniquingMap.try_emplace(UniqueMapKey); } else { StringRef UniqueMapKey = Section.getSingleStringRef(); SectionLen = UniqueMapKey.size(); - EntryNewPair = ELFUniquingMap.insert(std::make_pair(UniqueMapKey, nullptr)); + EntryNewPair = ELFUniquingMap.try_emplace(UniqueMapKey); } if (!EntryNewPair.second) @@ -696,10 +696,8 @@ MCSectionGOFF *MCContext::getGOFFSection(StringRef Section, SectionKind Kind, MCSection *Parent, uint32_t Subsection) { // Do the lookup. If we don't have a hit, return a new section. - auto IterBool = - GOFFUniquingMap.insert(std::make_pair(Section.str(), nullptr)); - auto Iter = IterBool.first; - if (!IterBool.second) + auto [Iter, Inserted] = GOFFUniquingMap.try_emplace(Section.str()); + if (!Inserted) return Iter->second; StringRef CachedName = Iter->first; @@ -731,9 +729,8 @@ MCSectionCOFF *MCContext::getCOFFSection(StringRef Section, // Do the lookup, if we have a hit, return it. COFFSectionKey T{Section, COMDATSymName, Selection, UniqueID}; - auto IterBool = COFFUniquingMap.insert(std::make_pair(T, nullptr)); - auto Iter = IterBool.first; - if (!IterBool.second) + auto [Iter, Inserted] = COFFUniquingMap.try_emplace(T); + if (!Inserted) return Iter->second; StringRef CachedName = Iter->first.SectionName;