[cfe-commits] r103429 - in /cfe/trunk: include/clang/AST/DeclarationName.h lib/AST/ASTContext.cpp lib/AST/DeclarationName.cpp

Ted Kremenek kremenek at apple.com
Mon May 10 13:56:10 PDT 2010


Author: kremenek
Date: Mon May 10 15:56:10 2010
New Revision: 103429

URL: http://llvm.org/viewvc/llvm-project?rev=103429&view=rev
Log:
Allocate most of DeclarationNamesTable using ASTContext's allcocator.  The only things that
aren't allocated this way are the internal FoldingSets.

Modified:
    cfe/trunk/include/clang/AST/DeclarationName.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/AST/DeclarationName.cpp

Modified: cfe/trunk/include/clang/AST/DeclarationName.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclarationName.h?rev=103429&r1=103428&r2=103429&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclarationName.h (original)
+++ cfe/trunk/include/clang/AST/DeclarationName.h Mon May 10 15:56:10 2010
@@ -314,6 +314,7 @@
 /// retrieved using its member functions (e.g.,
 /// getCXXConstructorName).
 class DeclarationNameTable {
+  ASTContext &Ctx;
   void *CXXSpecialNamesImpl; // Actually a FoldingSet<CXXSpecialName> *
   CXXOperatorIdName *CXXOperatorNames; // Operator names
   void *CXXLiteralOperatorNames; // Actually a CXXOperatorIdName*
@@ -325,10 +326,6 @@
   DeclarationNameTable(ASTContext &C);
   ~DeclarationNameTable();
 
-  /// Free all memory allocated associated with this DeclarationTable that
-  //  is used allocated using the specified ASTContext object.
-  void DoDestroy(ASTContext &C);
-
   /// getIdentifier - Create a declaration name that is a simple
   /// identifier.
   DeclarationName getIdentifier(const IdentifierInfo *ID) {

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=103429&r1=103428&r2=103429&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon May 10 15:56:10 2010
@@ -110,9 +110,6 @@
   if (GlobalNestedNameSpecifier)
     GlobalNestedNameSpecifier->Destroy(*this);
 
-  // Deallocate the memory associated with the DeclarationNameTable.
-  DeclarationNames.DoDestroy(*this);
-
   TUDecl->Destroy(*this);
 }
 

Modified: cfe/trunk/lib/AST/DeclarationName.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclarationName.cpp?rev=103429&r1=103428&r2=103429&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclarationName.cpp (original)
+++ cfe/trunk/lib/AST/DeclarationName.cpp Mon May 10 15:56:10 2010
@@ -384,12 +384,12 @@
   llvm::errs() << '\n';
 }
 
-DeclarationNameTable::DeclarationNameTable(ASTContext &C) {
+DeclarationNameTable::DeclarationNameTable(ASTContext &C) : Ctx(C) {
   CXXSpecialNamesImpl = new llvm::FoldingSet<CXXSpecialName>;
   CXXLiteralOperatorNames = new llvm::FoldingSet<CXXLiteralOperatorIdName>;
 
   // Initialize the overloaded operator names.
-  CXXOperatorNames = new (C) CXXOperatorIdName[NUM_OVERLOADED_OPERATORS];
+  CXXOperatorNames = new (Ctx) CXXOperatorIdName[NUM_OVERLOADED_OPERATORS];
   for (unsigned Op = 0; Op < NUM_OVERLOADED_OPERATORS; ++Op) {
     CXXOperatorNames[Op].ExtraKindOrNumArgs
       = Op + DeclarationNameExtra::CXXConversionFunction;
@@ -400,36 +400,34 @@
 DeclarationNameTable::~DeclarationNameTable() {
   llvm::FoldingSet<CXXSpecialName> *SpecialNames =
     static_cast<llvm::FoldingSet<CXXSpecialName>*>(CXXSpecialNamesImpl);
-  llvm::FoldingSetIterator<CXXSpecialName>
-                           SI = SpecialNames->begin(), SE = SpecialNames->end();
-
-  while (SI != SE) {
-    CXXSpecialName *n = &*SI++;
-    delete n;
-  }
-
-
   llvm::FoldingSet<CXXLiteralOperatorIdName> *LiteralNames
     = static_cast<llvm::FoldingSet<CXXLiteralOperatorIdName>*>
-                                                      (CXXLiteralOperatorNames);
-  llvm::FoldingSetIterator<CXXLiteralOperatorIdName>
-                           LI = LiteralNames->begin(), LE = LiteralNames->end();
+        (CXXLiteralOperatorNames);
 
-  while (LI != LE) {
-    CXXLiteralOperatorIdName *n = &*LI++;
-    delete n;
+  if (Ctx.FreeMemory) {
+    llvm::FoldingSetIterator<CXXSpecialName>
+      SI = SpecialNames->begin(), SE = SpecialNames->end();
+
+    while (SI != SE) {
+      CXXSpecialName *n = &*SI++;
+      Ctx.Deallocate(n);
+    }
+
+    llvm::FoldingSetIterator<CXXLiteralOperatorIdName>
+      LI = LiteralNames->begin(), LE = LiteralNames->end();
+
+    while (LI != LE) {
+      CXXLiteralOperatorIdName *n = &*LI++;
+      Ctx.Deallocate(n);
+    }
+
+    Ctx.Deallocate(CXXOperatorNames);
   }
 
   delete SpecialNames;
   delete LiteralNames;
 }
 
-void DeclarationNameTable::DoDestroy(ASTContext &C) {
-  if (C.FreeMemory) {
-    C.Deallocate(CXXOperatorNames);
-  }
-}
-
 DeclarationName
 DeclarationNameTable::getCXXSpecialName(DeclarationName::NameKind Kind,
                                         CanQualType Ty) {
@@ -465,7 +463,7 @@
   if (CXXSpecialName *Name = SpecialNames->FindNodeOrInsertPos(ID, InsertPos))
     return DeclarationName(Name);
 
-  CXXSpecialName *SpecialName = new CXXSpecialName;
+  CXXSpecialName *SpecialName = new (Ctx) CXXSpecialName;
   SpecialName->ExtraKindOrNumArgs = EKind;
   SpecialName->Type = Ty;
   SpecialName->FETokenInfo = 0;
@@ -493,7 +491,7 @@
                                LiteralNames->FindNodeOrInsertPos(ID, InsertPos))
     return DeclarationName (Name);
   
-  CXXLiteralOperatorIdName *LiteralName = new CXXLiteralOperatorIdName;
+  CXXLiteralOperatorIdName *LiteralName = new (Ctx) CXXLiteralOperatorIdName;
   LiteralName->ExtraKindOrNumArgs = DeclarationNameExtra::CXXLiteralOperator;
   LiteralName->ID = II;
 





More information about the cfe-commits mailing list