From 72e2b35f3c893fe7fe26df0461eb2da475fdb107 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Thu, 6 Feb 2025 16:29:16 -0800 Subject: [PATCH] [ObjectYAML] Avoid repeated hash lookups (NFC) --- llvm/lib/ObjectYAML/DWARFEmitter.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) 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) {