Skip to content

Commit a8289a3

Browse files
[Tooling] Avoid repeated hash lookups (NFC) (#111469)
1 parent dec641e commit a8289a3

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

clang/lib/Tooling/Inclusions/HeaderIncludes.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,9 @@ HeaderIncludes::HeaderIncludes(StringRef FileName, StringRef Code,
320320
// - If CategoryEndOffset[Priority] isn't set, use the next higher value
321321
// that is set, up to CategoryEndOffset[Highest].
322322
auto Highest = Priorities.begin();
323-
if (CategoryEndOffsets.find(*Highest) == CategoryEndOffsets.end()) {
324-
if (FirstIncludeOffset >= 0)
325-
CategoryEndOffsets[*Highest] = FirstIncludeOffset;
326-
else
327-
CategoryEndOffsets[*Highest] = MinInsertOffset;
328-
}
323+
auto [It, Inserted] = CategoryEndOffsets.try_emplace(*Highest);
324+
if (Inserted)
325+
It->second = FirstIncludeOffset >= 0 ? FirstIncludeOffset : MinInsertOffset;
329326
// By this point, CategoryEndOffset[Highest] is always set appropriately:
330327
// - to an appropriate location before/after existing #includes, or
331328
// - to right after the header guard, or

0 commit comments

Comments
 (0)