Skip to content

Commit 0f47627

Browse files
[ObjectYAML] Avoid repeated hash lookups (NFC) (#111938)
1 parent 2acec3e commit 0f47627

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

llvm/lib/ObjectYAML/COFFEmitter.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,12 @@ struct COFFParser {
125125
}
126126

127127
unsigned getStringIndex(StringRef Str) {
128-
StringMap<unsigned>::iterator i = StringTableMap.find(Str);
129-
if (i == StringTableMap.end()) {
130-
unsigned Index = StringTable.size();
128+
auto [It, Inserted] = StringTableMap.try_emplace(Str, StringTable.size());
129+
if (Inserted) {
131130
StringTable.append(Str.begin(), Str.end());
132131
StringTable.push_back(0);
133-
StringTableMap[Str] = Index;
134-
return Index;
135132
}
136-
return i->second;
133+
return It->second;
137134
}
138135

139136
COFFYAML::Object &Obj;

0 commit comments

Comments
 (0)