https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/127300
None >From 99becba2d947d6f18ef6f2cfbf583b28bcd21713 Mon Sep 17 00:00:00 2001 From: Kazu Hirata <k...@google.com> Date: Fri, 14 Feb 2025 02:44:22 -0800 Subject: [PATCH] [Index] Avoid repeated hash lookups (NFC) --- clang/lib/Index/USRGeneration.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) 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>()) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits