[clang] [Tooling] Avoid repeated hash lookups (NFC) (PR #111469)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 7 19:46:25 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/111469
None
>From 63f32da83241327082af3baa57f59480d9825e47 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 7 Oct 2024 07:06:16 -0700
Subject: [PATCH] [Tooling] Avoid repeated hash lookups (NFC)
---
clang/lib/Tooling/Inclusions/HeaderIncludes.cpp | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
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