Skip to content

Commit dbb20fc

Browse files
[ObjectYAML] Avoid repeated hash lookups (NFC) (#126187)
1 parent 46f5662 commit dbb20fc

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

llvm/lib/ObjectYAML/DWARFEmitter.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,11 @@ Error DWARFYAML::emitDebugStr(raw_ostream &OS, const DWARFYAML::Data &DI) {
9696
StringRef DWARFYAML::Data::getAbbrevTableContentByIndex(uint64_t Index) const {
9797
assert(Index < DebugAbbrev.size() &&
9898
"Index should be less than the size of DebugAbbrev array");
99-
auto It = AbbrevTableContents.find(Index);
100-
if (It != AbbrevTableContents.cend())
99+
auto [It, Inserted] = AbbrevTableContents.try_emplace(Index);
100+
if (!Inserted)
101101
return It->second;
102102

103-
std::string AbbrevTableBuffer;
104-
raw_string_ostream OS(AbbrevTableBuffer);
103+
raw_string_ostream OS(It->second);
105104

106105
uint64_t AbbrevCode = 0;
107106
for (const DWARFYAML::Abbrev &AbbrevDecl : DebugAbbrev[Index].Table) {
@@ -123,9 +122,7 @@ StringRef DWARFYAML::Data::getAbbrevTableContentByIndex(uint64_t Index) const {
123122
// consisting of a 0 byte for the abbreviation code.
124123
OS.write_zeros(1);
125124

126-
AbbrevTableContents.insert({Index, AbbrevTableBuffer});
127-
128-
return AbbrevTableContents[Index];
125+
return It->second;
129126
}
130127

131128
Error DWARFYAML::emitDebugAbbrev(raw_ostream &OS, const DWARFYAML::Data &DI) {

0 commit comments

Comments
 (0)