From 45d9c2d2b1b4ada29160edadc071db9779c0ec07 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Mon, 10 May 2010 20:56:10 +0000 Subject: [PATCH] Allocate most of DeclarationNamesTable using ASTContext's allcocator. The only things that aren't allocated this way are the internal FoldingSets. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103429 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclarationName.h | 5 +--- lib/AST/ASTContext.cpp | 3 -- lib/AST/DeclarationName.cpp | 46 ++++++++++++++--------------- 3 files changed, 23 insertions(+), 31 deletions(-) diff --git a/include/clang/AST/DeclarationName.h b/include/clang/AST/DeclarationName.h index 6e8316014e..8a771d513c 100644 --- a/include/clang/AST/DeclarationName.h +++ b/include/clang/AST/DeclarationName.h @@ -314,6 +314,7 @@ inline bool operator>=(DeclarationName LHS, DeclarationName RHS) { /// retrieved using its member functions (e.g., /// getCXXConstructorName). class DeclarationNameTable { + ASTContext &Ctx; void *CXXSpecialNamesImpl; // Actually a FoldingSet * CXXOperatorIdName *CXXOperatorNames; // Operator names void *CXXLiteralOperatorNames; // Actually a CXXOperatorIdName* @@ -325,10 +326,6 @@ public: 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) { diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 3a8084833e..71ef09ab18 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -110,9 +110,6 @@ ASTContext::~ASTContext() { if (GlobalNestedNameSpecifier) GlobalNestedNameSpecifier->Destroy(*this); - // Deallocate the memory associated with the DeclarationNameTable. - DeclarationNames.DoDestroy(*this); - TUDecl->Destroy(*this); } diff --git a/lib/AST/DeclarationName.cpp b/lib/AST/DeclarationName.cpp index 0623283385..343d403e76 100644 --- a/lib/AST/DeclarationName.cpp +++ b/lib/AST/DeclarationName.cpp @@ -384,12 +384,12 @@ void DeclarationName::dump() const { llvm::errs() << '\n'; } -DeclarationNameTable::DeclarationNameTable(ASTContext &C) { +DeclarationNameTable::DeclarationNameTable(ASTContext &C) : Ctx(C) { CXXSpecialNamesImpl = new llvm::FoldingSet; CXXLiteralOperatorNames = new llvm::FoldingSet; // 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(ASTContext &C) { DeclarationNameTable::~DeclarationNameTable() { llvm::FoldingSet *SpecialNames = static_cast*>(CXXSpecialNamesImpl); - llvm::FoldingSetIterator - SI = SpecialNames->begin(), SE = SpecialNames->end(); + llvm::FoldingSet *LiteralNames + = static_cast*> + (CXXLiteralOperatorNames); - while (SI != SE) { - CXXSpecialName *n = &*SI++; - delete n; - } + if (Ctx.FreeMemory) { + llvm::FoldingSetIterator + SI = SpecialNames->begin(), SE = SpecialNames->end(); + while (SI != SE) { + CXXSpecialName *n = &*SI++; + Ctx.Deallocate(n); + } - llvm::FoldingSet *LiteralNames - = static_cast*> - (CXXLiteralOperatorNames); - llvm::FoldingSetIterator - LI = LiteralNames->begin(), LE = LiteralNames->end(); + llvm::FoldingSetIterator + LI = LiteralNames->begin(), LE = LiteralNames->end(); + + while (LI != LE) { + CXXLiteralOperatorIdName *n = &*LI++; + Ctx.Deallocate(n); + } - while (LI != LE) { - CXXLiteralOperatorIdName *n = &*LI++; - delete 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 @@ DeclarationNameTable::getCXXSpecialName(DeclarationName::NameKind Kind, 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 @@ DeclarationNameTable::getCXXLiteralOperatorName(IdentifierInfo *II) { LiteralNames->FindNodeOrInsertPos(ID, InsertPos)) return DeclarationName (Name); - CXXLiteralOperatorIdName *LiteralName = new CXXLiteralOperatorIdName; + CXXLiteralOperatorIdName *LiteralName = new (Ctx) CXXLiteralOperatorIdName; LiteralName->ExtraKindOrNumArgs = DeclarationNameExtra::CXXLiteralOperator; LiteralName->ID = II; -- 2.50.0