[clang] a8289a3 - [Tooling] Avoid repeated hash lookups (NFC) (#111469)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 8 07:28:58 PDT 2024
Author: Kazu Hirata
Date: 2024-10-08T07:28:53-07:00
New Revision: a8289a35d06b9f7cb3d9b18dba6be0f1f0a8a898
URL: https://github.com/llvm/llvm-project/commit/a8289a35d06b9f7cb3d9b18dba6be0f1f0a8a898
DIFF: https://github.com/llvm/llvm-project/commit/a8289a35d06b9f7cb3d9b18dba6be0f1f0a8a898.diff
LOG: [Tooling] Avoid repeated hash lookups (NFC) (#111469)
Added:
Modified:
clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
Removed:
################################################################################
diff --git a/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp b/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
index 4313da66efc0b7..0cb96097415ea8 100644
--- a/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ b/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -320,12 +320,9 @@ HeaderIncludes::HeaderIncludes(StringRef FileName, StringRef Code,
// - If CategoryEndOffset[Priority] isn't set, use the next higher value
// that is set, up to CategoryEndOffset[Highest].
auto Highest = Priorities.begin();
- if (CategoryEndOffsets.find(*Highest) == CategoryEndOffsets.end()) {
- if (FirstIncludeOffset >= 0)
- CategoryEndOffsets[*Highest] = FirstIncludeOffset;
- else
- CategoryEndOffsets[*Highest] = MinInsertOffset;
- }
+ auto [It, Inserted] = CategoryEndOffsets.try_emplace(*Highest);
+ if (Inserted)
+ It->second = FirstIncludeOffset >= 0 ? FirstIncludeOffset : MinInsertOffset;
// By this point, CategoryEndOffset[Highest] is always set appropriately:
// - to an appropriate location before/after existing #includes, or
// - to right after the header guard, or
More information about the cfe-commits
mailing list