Skip to content

Commit f964377

Browse files
[DebugInfo] Avoid repeated hash lookups (NFC) (#128127)
1 parent b044350 commit f964377

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewVisitor.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,29 +155,23 @@ class LVForwardReferences {
155155
}
156156

157157
void add(StringRef Name, TypeIndex TIForward) {
158-
if (ForwardTypesNames.find(Name) == ForwardTypesNames.end()) {
159-
ForwardTypesNames.emplace(
160-
std::piecewise_construct, std::forward_as_tuple(Name),
161-
std::forward_as_tuple(TIForward, TypeIndex::None()));
162-
} else {
158+
auto [It, Inserted] =
159+
ForwardTypesNames.try_emplace(Name, TIForward, TypeIndex::None());
160+
if (!Inserted) {
163161
// Update a recorded definition with its reference.
164-
ForwardTypesNames[Name].first = TIForward;
165-
add(TIForward, ForwardTypesNames[Name].second);
162+
It->second.first = TIForward;
163+
add(TIForward, It->second.second);
166164
}
167165
}
168166

169167
// Update a previously recorded forward reference with its definition.
170168
void update(StringRef Name, TypeIndex TIReference) {
171-
auto It = ForwardTypesNames.find(Name);
172-
if (It != ForwardTypesNames.end()) {
169+
auto [It, Inserted] =
170+
ForwardTypesNames.try_emplace(Name, TypeIndex::None(), TIReference);
171+
if (!Inserted) {
173172
// Update the recorded forward reference with its definition.
174173
It->second.second = TIReference;
175174
add(It->second.first, TIReference);
176-
} else {
177-
// We have not seen the forward reference. Insert the definition.
178-
ForwardTypesNames.emplace(
179-
std::piecewise_construct, std::forward_as_tuple(Name),
180-
std::forward_as_tuple(TypeIndex::None(), TIReference));
181175
}
182176
}
183177

0 commit comments

Comments
 (0)