]> granicus.if.org Git - clang/commitdiff
partially inline getAttrs() to speed up PR3810 (and lots of
authorChris Lattner <sabre@nondot.org>
Sat, 21 Mar 2009 06:27:31 +0000 (06:27 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 21 Mar 2009 06:27:31 +0000 (06:27 +0000)
other code presumably) by 4.3%

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67430 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclBase.h
lib/AST/DeclBase.cpp

index 86d96a5b1ce68a9b5b92c0f48d1b2ccd3a8d0a04..abf5404882bc9172e382b2f8fba18942662ac224 100644 (file)
@@ -180,7 +180,10 @@ public:
 
   bool hasAttrs() const { return HasAttrs; }
   void addAttr(Attr *attr);
-  const Attr *getAttrs() const;
+  const Attr *getAttrs() const {
+    if (!HasAttrs) return 0;  // common case, no attributes.
+    return getAttrsImpl();    // Uncommon case, out of line hash lookup.
+  }
   void swapAttrs(Decl *D);
   void invalidateAttrs();
 
@@ -188,7 +191,6 @@ public:
     for (const Attr *attr = getAttrs(); attr; attr = attr->getNext())
       if (const T *V = dyn_cast<T>(attr))
         return V;
-
     return 0;
   }
     
@@ -326,6 +328,9 @@ protected:
     // FIXME: This will eventually be a pure virtual function.
     assert (false && "Not implemented.");
   }
+private:
+  const Attr *getAttrsImpl() const;
+
 };
 
 /// PrettyStackTraceDecl - If a crash occurs, indicate that it happened when
index 1e7ef549b43472cd171b54861b2a201dc2685fc7..812c362acd37f1dd082839a2c1223f8d7b408c49 100644 (file)
@@ -171,10 +171,8 @@ void Decl::invalidateAttrs() {
   }
 }
 
-const Attr *Decl::getAttrs() const {
-  if (!HasAttrs)
-    return 0;
-  
+const Attr *Decl::getAttrsImpl() const {
+  assert(HasAttrs && "getAttrs() should verify this!"); 
   return (*DeclAttrs)[this];
 }