From e30d1ca09ca613dac98345c3dd9ec0bd6b7cda66 Mon Sep 17 00:00:00 2001 From: Kazu Hirata 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 9faf2a8a17341..ad2ebb6cd6e6c 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(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 FoundForFile = - getASTUnitForFile(NameFileMap[FunctionName], DisplayCTUProgress)) { + getASTUnitForFile(It->second, DisplayCTUProgress)) { // Update the cache. NameASTUnitMap[FunctionName] = *FoundForFile;