[clang] 8bdc312 - [Index] Avoid repeated hash lookups (NFC) (#127300)

via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 15 01:35:36 PST 2025


Author: Kazu Hirata
Date: 2025-02-15T01:35:33-08:00
New Revision: 8bdc312272543e8fb21868e57a6c1592668b49a4

URL: https://github.com/llvm/llvm-project/commit/8bdc312272543e8fb21868e57a6c1592668b49a4
DIFF: https://github.com/llvm/llvm-project/commit/8bdc312272543e8fb21868e57a6c1592668b49a4.diff

LOG: [Index] Avoid repeated hash lookups (NFC) (#127300)

Added: 
    

Modified: 
    clang/lib/Index/USRGeneration.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp
index 1e54b413dc59c..0a5a1bcc74865 100644
--- a/clang/lib/Index/USRGeneration.cpp
+++ b/clang/lib/Index/USRGeneration.cpp
@@ -859,16 +859,12 @@ void USRGenerator::VisitType(QualType T) {
     }
 
     // If we have already seen this (non-built-in) type, use a substitution
-    // encoding.
-    llvm::DenseMap<const Type *, unsigned>::iterator Substitution
-      = TypeSubstitutions.find(T.getTypePtr());
-    if (Substitution != TypeSubstitutions.end()) {
+    // encoding.  Otherwise, record this as a substitution.
+    auto [Substitution, Inserted] =
+        TypeSubstitutions.try_emplace(T.getTypePtr(), TypeSubstitutions.size());
+    if (!Inserted) {
       Out << 'S' << Substitution->second << '_';
       return;
-    } else {
-      // Record this as a substitution.
-      unsigned Number = TypeSubstitutions.size();
-      TypeSubstitutions[T.getTypePtr()] = Number;
     }
 
     if (const PointerType *PT = T->getAs<PointerType>()) {


        


More information about the cfe-commits mailing list