From: Chris Lattner Date: Fri, 27 Mar 2009 20:18:19 +0000 (+0000) Subject: minor cleanups: make getIdentifierNamespace() be a single load X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=769dbdf467681f6020ff248b969c2d41a4fdccd3;p=clang minor cleanups: make getIdentifierNamespace() be a single load instead of a load + large inlined switch. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67864 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index 982da7493e..86626fe388 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -144,6 +144,9 @@ private: /// the implementation rather than explicitly written by the user. bool Implicit : 1; + /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in. + unsigned IdentifierNamespace : 5; + #ifndef NDEBUG void CheckAccessDeclContext() const; #else @@ -160,7 +163,8 @@ protected: : NextDeclarator(0), NextDeclInScope(0), DeclCtx(DC, 0), Loc(L), DeclKind(DK), InvalidDecl(0), - HasAttrs(false), Implicit(false), Access(AS_none) { + HasAttrs(false), Implicit(false), + IdentifierNamespace(getIdentifierNamespaceForKind(DK)), Access(AS_none) { if (Decl::CollectingStats()) addDeclKind(DK); } @@ -224,57 +228,13 @@ public: void setImplicit(bool I = true) { Implicit = I; } unsigned getIdentifierNamespace() const { - switch (DeclKind) { - default: - if (DeclKind >= FunctionFirst && DeclKind <= FunctionLast) - return IDNS_Ordinary; - assert(0 && "Unknown decl kind!"); - case OverloadedFunction: - case Typedef: - case EnumConstant: - case Var: - case ImplicitParam: - case ParmVar: - case OriginalParmVar: - case NonTypeTemplateParm: - case ObjCMethod: - case ObjCContainer: - case ObjCCategory: - case ObjCInterface: - case ObjCCategoryImpl: - case ObjCProperty: - case ObjCCompatibleAlias: - return IDNS_Ordinary; - - case ObjCProtocol: - return IDNS_Protocol; - - case Field: - case ObjCAtDefsField: - case ObjCIvar: - return IDNS_Member; - - case Record: - case CXXRecord: - case Enum: - case TemplateTypeParm: - return IDNS_Tag; - - case Namespace: - case Template: - case FunctionTemplate: - case ClassTemplate: - case TemplateTemplateParm: - return IDNS_Tag | IDNS_Ordinary; - - case ClassTemplateSpecialization: - return 0; - } + return IdentifierNamespace; } - bool isInIdentifierNamespace(unsigned NS) const { return getIdentifierNamespace() & NS; } + static unsigned getIdentifierNamespaceForKind(Kind DK); + /// getLexicalDeclContext - The declaration context where this Decl was /// lexically declared (LexicalDC). May be different from @@ -398,8 +358,7 @@ class DeclContext { /// in the 3 lowest-order bits and the upper bits are treated as a /// pointer to an array of NamedDecl pointers. If the context /// contains seven or more declarations, the upper bits are treated - /// as a pointer to a DenseMap>. - /// FIXME: We need a better data structure for this. + /// as a pointer to a DenseMap. llvm::PointerIntPair LookupPtr; /// FirstDecl - The first declaration stored within this declaration diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index ef9dc7622f..72ac555220 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -117,6 +117,14 @@ void PrettyStackTraceDecl::print(llvm::raw_ostream &OS) const { // Decl Implementation //===----------------------------------------------------------------------===// +// Out-of-line virtual method providing a home for Decl. +Decl::~Decl() { + if (isOutOfSemaDC()) + delete getMultipleDC(); + + assert(!HasAttrs && "attributes should have been freed by Destroy"); +} + void Decl::setDeclContext(DeclContext *DC) { if (isOutOfSemaDC()) delete getMultipleDC(); @@ -140,12 +148,66 @@ void Decl::setLexicalDeclContext(DeclContext *DC) { } } -// Out-of-line virtual method providing a home for Decl. -Decl::~Decl() { - if (isOutOfSemaDC()) - delete getMultipleDC(); - - assert(!HasAttrs && "attributes should have been freed by Destroy"); +unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) { + switch (DeclKind) { + default: + if (DeclKind >= FunctionFirst && DeclKind <= FunctionLast) + return IDNS_Ordinary; + assert(0 && "Unknown decl kind!"); + case OverloadedFunction: + case Typedef: + case EnumConstant: + case Var: + case ImplicitParam: + case ParmVar: + case OriginalParmVar: + case NonTypeTemplateParm: + case ObjCMethod: + case ObjCContainer: + case ObjCCategory: + case ObjCInterface: + case ObjCCategoryImpl: + case ObjCProperty: + case ObjCCompatibleAlias: + return IDNS_Ordinary; + + case ObjCProtocol: + return IDNS_Protocol; + + case Field: + case ObjCAtDefsField: + case ObjCIvar: + return IDNS_Member; + + case Record: + case CXXRecord: + case Enum: + case TemplateTypeParm: + return IDNS_Tag; + + case Namespace: + case Template: + case FunctionTemplate: + case ClassTemplate: + case TemplateTemplateParm: + return IDNS_Tag | IDNS_Ordinary; + + // Never have names. + case LinkageSpec: + case FileScopeAsm: + case StaticAssert: + case ObjCClass: + case ObjCImplementation: + case ObjCPropertyImpl: + case ObjCForwardProtocol: + case Block: + case TranslationUnit: + + // Aren't looked up? + case UsingDirective: + case ClassTemplateSpecialization: + return 0; + } } void Decl::addAttr(Attr *NewAttr) { @@ -426,8 +488,7 @@ private: typedef llvm::DenseMap StoredDeclsMap; DeclContext::~DeclContext() { - unsigned Size = LookupPtr.getInt(); - if (Size == LookupIsMap) + if (isLookupMap()) delete static_cast(LookupPtr.getPointer()); else delete [] static_cast(LookupPtr.getPointer());