Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ObjectYAML] Avoid repeated hash lookups (NFC) #126187

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions llvm/lib/ObjectYAML/DWARFEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down