[clang] [CrossTU] Avoid repeated hash lookups (NFC) (PR #126380)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 8 09:19:40 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/126380
None
>From e30d1ca09ca613dac98345c3dd9ec0bd6b7cda66 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 8 Feb 2025 00:57:25 -0800
Subject: [PATCH] [CrossTU] Avoid repeated hash lookups (NFC)
---
clang/lib/CrossTU/CrossTranslationUnit.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp b/clang/lib/CrossTU/CrossTranslationUnit.cpp
index 9faf2a8a173411b..ad2ebb6cd6e6c80 100644
--- a/clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -453,7 +453,8 @@ CrossTranslationUnitContext::ASTUnitStorage::getASTUnitForFunction(
return std::move(IndexLoadError);
// Check if there is an entry in the index for the function.
- if (!NameFileMap.count(FunctionName)) {
+ auto It = NameFileMap.find(FunctionName);
+ if (It == NameFileMap.end()) {
++NumNotInOtherTU;
return llvm::make_error<IndexError>(index_error_code::missing_definition);
}
@@ -461,7 +462,7 @@ CrossTranslationUnitContext::ASTUnitStorage::getASTUnitForFunction(
// Search in the index for the filename where the definition of FunctionName
// resides.
if (llvm::Expected<ASTUnit *> FoundForFile =
- getASTUnitForFile(NameFileMap[FunctionName], DisplayCTUProgress)) {
+ getASTUnitForFile(It->second, DisplayCTUProgress)) {
// Update the cache.
NameASTUnitMap[FunctionName] = *FoundForFile;
More information about the cfe-commits
mailing list