[clang] 5ad4959 - [clang] Unique NamespaceAndPrefixStorages with a UniquingSet (NFC) (#224221)

via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 27 15:22:08 PDT 2026


Author: Kazu Hirata
Date: 2026-09-27T15:22:02-07:00
New Revision: 5ad4959a040a6e31eba7ab46f3bf4fd41cd224dc

URL: https://github.com/llvm/llvm-project/commit/5ad4959a040a6e31eba7ab46f3bf4fd41cd224dc
DIFF: https://github.com/llvm/llvm-project/commit/5ad4959a040a6e31eba7ab46f3bf4fd41cd224dc.diff

LOG: [clang] Unique NamespaceAndPrefixStorages with a UniquingSet (NFC) (#224221)

This patch migrates NamespaceAndPrefixStorages in ASTContext from
llvm::FoldingSet to llvm::UniquingSet.

NamespaceAndPrefixStorage keys on a pair of const NamespaceBaseDecl *
and NestedNameSpecifier.  Switching to UniquingSet allows us to look
up storages with a typed key, eliminating FoldingSetNodeID
serialization at lookup sites and removing
NamespaceAndPrefixStorage::Profile.

Assisted-by: Antigravity

Added: 
    

Modified: 
    clang/include/clang/AST/ASTContext.h
    clang/include/clang/AST/NestedNameSpecifierBase.h
    clang/lib/AST/NestedNameSpecifier.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index b2d407e412b3d..8dfca9eefd3a7 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -345,7 +345,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
   /// Internal storage for NestedNameSpecifiers.
   ///
   /// This set is managed by the NestedNameSpecifier class.
-  mutable llvm::FoldingSet<NamespaceAndPrefixStorage>
+  mutable llvm::UniquingSet<NamespaceAndPrefixStorage>
       NamespaceAndPrefixStorages;
 
   /// A cache mapping from RecordDecls to ASTRecordLayouts.

diff  --git a/clang/include/clang/AST/NestedNameSpecifierBase.h b/clang/include/clang/AST/NestedNameSpecifierBase.h
index 5d883246252a1..f5d11e589a0b1 100644
--- a/clang/include/clang/AST/NestedNameSpecifierBase.h
+++ b/clang/include/clang/AST/NestedNameSpecifierBase.h
@@ -265,12 +265,8 @@ struct alignas(8) NamespaceAndPrefixStorage : NamespaceAndPrefix,
   NamespaceAndPrefixStorage(const NamespaceBaseDecl *Namespace,
                             NestedNameSpecifier Prefix)
       : NamespaceAndPrefix{Namespace, Prefix} {}
-  void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, Namespace, Prefix); }
-  static void Profile(llvm::FoldingSetNodeID &ID,
-                      const NamespaceBaseDecl *Namespace,
-                      NestedNameSpecifier Prefix) {
-    ID.AddPointer(Namespace);
-    Prefix.Profile(ID);
+  std::pair<const NamespaceBaseDecl *, NestedNameSpecifier> getKey() const {
+    return {Namespace, Prefix};
   }
 };
 

diff  --git a/clang/lib/AST/NestedNameSpecifier.cpp b/clang/lib/AST/NestedNameSpecifier.cpp
index b668a61021800..1eca017a81e24 100644
--- a/clang/lib/AST/NestedNameSpecifier.cpp
+++ b/clang/lib/AST/NestedNameSpecifier.cpp
@@ -38,12 +38,9 @@ const NamespaceAndPrefixStorage *
 NestedNameSpecifier::MakeNamespaceAndPrefixStorage(
     const ASTContext &Ctx, const NamespaceBaseDecl *Namespace,
     NestedNameSpecifier Prefix) {
-  llvm::FoldingSetNodeID ID;
-  NamespaceAndPrefixStorage::Profile(ID, Namespace, Prefix);
-
   llvm::FoldingSetInsertToken Token;
   NamespaceAndPrefixStorage *S =
-      Ctx.NamespaceAndPrefixStorages.lookup(ID, Token);
+      Ctx.NamespaceAndPrefixStorages.lookup({Namespace, Prefix}, Token);
   if (!S) {
     S = new (Ctx, alignof(NamespaceAndPrefixStorage))
         NamespaceAndPrefixStorage(Namespace, Prefix);


        


More information about the cfe-commits mailing list