diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp index 421dfe7dfa30e..ec5e08082b0ca 100644 --- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp +++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp @@ -96,12 +96,11 @@ Error DWARFYAML::emitDebugStr(raw_ostream &OS, const DWARFYAML::Data &DI) { StringRef DWARFYAML::Data::getAbbrevTableContentByIndex(uint64_t Index) const { assert(Index < DebugAbbrev.size() && "Index should be less than the size of DebugAbbrev array"); - auto It = AbbrevTableContents.find(Index); - if (It != AbbrevTableContents.cend()) + auto [It, Inserted] = AbbrevTableContents.try_emplace(Index); + if (!Inserted) return It->second; - std::string AbbrevTableBuffer; - raw_string_ostream OS(AbbrevTableBuffer); + raw_string_ostream OS(It->second); uint64_t AbbrevCode = 0; for (const DWARFYAML::Abbrev &AbbrevDecl : DebugAbbrev[Index].Table) { @@ -123,9 +122,7 @@ StringRef DWARFYAML::Data::getAbbrevTableContentByIndex(uint64_t Index) const { // consisting of a 0 byte for the abbreviation code. OS.write_zeros(1); - AbbrevTableContents.insert({Index, AbbrevTableBuffer}); - - return AbbrevTableContents[Index]; + return It->second; } Error DWARFYAML::emitDebugAbbrev(raw_ostream &OS, const DWARFYAML::Data &DI) {