[cfe-commits] r65132 - in /cfe/trunk: Driver/RewriteObjC.cpp include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp

Chris Lattner sabre at nondot.org
Fri Feb 20 10:18:36 PST 2009


Author: lattner
Date: Fri Feb 20 12:18:36 2009
New Revision: 65132

URL: http://llvm.org/viewvc/llvm-project?rev=65132&view=rev
Log:
remove some slow O(n) methods.

Modified:
    cfe/trunk/Driver/RewriteObjC.cpp
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/DeclObjC.cpp

Modified: cfe/trunk/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteObjC.cpp?rev=65132&r1=65131&r2=65132&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Fri Feb 20 12:18:36 2009
@@ -2693,7 +2693,7 @@
       const char *endHeader = SM->getCharacterData(L);
       endHeader += Lexer::MeasureTokenLength(L, *SM);
 
-      if (!CDecl->getReferencedProtocols().empty()) {
+      if (CDecl->protocol_begin() != CDecl->protocol_end()) {
         // advance to the end of the referenced protocols.
         while (endHeader < cursor && *endHeader != '>') endHeader++;
         endHeader++;
@@ -2869,7 +2869,8 @@
       continue;
            
     if (PDecl->instmeth_begin() != PDecl->instmeth_end()) {
-      unsigned NumMethods = PDecl->getNumInstanceMethods();
+      unsigned NumMethods = std::distance(PDecl->instmeth_begin(),
+                                          PDecl->instmeth_end());
       /* struct _objc_protocol_method_list {
        int protocol_method_count;
        struct protocol_methods protocols[];
@@ -2902,7 +2903,8 @@
     }
     
     // Output class methods declared in this protocol.
-    int NumMethods = PDecl->getNumClassMethods();
+    unsigned NumMethods = std::distance(PDecl->classmeth_begin(),
+                                        PDecl->classmeth_end());
     if (NumMethods > 0) {
       /* struct _objc_protocol_method_list {
        int protocol_method_count;
@@ -2973,7 +2975,7 @@
     }
     else
       Result += "0, ";
-    if (PDecl->getNumClassMethods() > 0) {
+    if (PDecl->classmeth_begin() != PDecl->classmeth_end()) {
       Result += "(struct _objc_protocol_method_list *)&_OBJC_PROTOCOL_CLASS_METHODS_";
       Result += PDecl->getNameAsString();
       Result += "\n";
@@ -3085,7 +3087,7 @@
   Result += ClassDecl->getNameAsString();
   Result += "\"\n";
   
-  if (IDecl->getNumInstanceMethods() > 0) {
+  if (IDecl->instmeth_begin() != IDecl->instmeth_end()) {
     Result += "\t, (struct _objc_method_list *)"
            "&_OBJC_CATEGORY_INSTANCE_METHODS_";
     Result += FullCategoryName;
@@ -3093,7 +3095,7 @@
   }
   else
     Result += "\t, 0\n";
-  if (IDecl->getNumClassMethods() > 0) {
+  if (IDecl->classmeth_begin() != IDecl->classmeth_end()) {
     Result += "\t, (struct _objc_method_list *)"
            "&_OBJC_CATEGORY_CLASS_METHODS_";
     Result += FullCategoryName;
@@ -3102,7 +3104,7 @@
   else
     Result += "\t, 0\n";
   
-  if (CDecl && !CDecl->getReferencedProtocols().empty()) {
+  if (CDecl && CDecl->protocol_begin() != CDecl->protocol_end()) {
     Result += "\t, (struct _objc_protocol_list *)&_OBJC_CATEGORY_PROTOCOLS_"; 
     Result += FullCategoryName;
     Result += "\n";
@@ -3303,7 +3305,7 @@
   }
   else
     Result += ", 0\n";
-  if (!CDecl->getReferencedProtocols().empty()) {
+  if (CDecl->protocol_begin() != CDecl->protocol_end()) {
     Result += "\t,0, (struct _objc_protocol_list *)&_OBJC_CLASS_PROTOCOLS_";
     Result += CDecl->getNameAsString();
     Result += ",0,0\n";
@@ -3356,7 +3358,7 @@
   }
   else
     Result += ",0,0";
-  if (!CDecl->getReferencedProtocols().empty()) {
+  if (CDecl->protocol_begin() != CDecl->protocol_end()) {
     Result += ", (struct _objc_protocol_list*)&_OBJC_CLASS_PROTOCOLS_";
     Result += CDecl->getNameAsString();
     Result += ", 0,0\n";

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=65132&r1=65131&r2=65132&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Feb 20 12:18:36 2009
@@ -308,11 +308,6 @@
 
   ObjCPropertyDecl *FindPropertyDeclaration(IdentifierInfo *PropertyId) const;
 
-  // Get the number of methods, properties. These methods are slow, O(n).
-  unsigned getNumInstanceMethods() const;
-  unsigned getNumClassMethods() const;
-  unsigned getNumProperties() const;
-  
   // Marks the end of the container.
   SourceLocation getAtEndLoc() const { return AtEndLoc; }
   void setAtEndLoc(SourceLocation L) { AtEndLoc = L; }
@@ -798,9 +793,6 @@
   const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
   ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
   
-  unsigned getNumInstanceMethods() const { return InstanceMethods.size(); }
-  unsigned getNumClassMethods() const { return ClassMethods.size(); }
-
   void addInstanceMethod(ObjCMethodDecl *method) {
     InstanceMethods.push_back(method);
   }

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=65132&r1=65131&r2=65132&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Fri Feb 20 12:18:36 2009
@@ -282,25 +282,6 @@
   return 0;
 }
 
-unsigned ObjCContainerDecl::getNumInstanceMethods() const {
-  unsigned sum = 0;
-  for (instmeth_iterator I=instmeth_begin(), E=instmeth_end(); I != E; ++I)
-    sum++;
-  return sum;
-}
-unsigned ObjCContainerDecl::getNumClassMethods() const { 
-  unsigned sum = 0;
-  for (classmeth_iterator I=classmeth_begin(), E=classmeth_end(); I != E; ++I)
-    sum++;
-  return sum;
-}
-unsigned ObjCContainerDecl::getNumProperties() const { 
-  unsigned sum = 0;
-  for (prop_iterator I=prop_begin(), E=prop_end(); I != E; ++I)
-    sum++;
-  return sum;
-}
-
 /// FindPropertyDeclaration - Finds declaration of the property given its name
 /// in 'PropertyId' and returns it. It returns 0, if not found.
 /// FIXME: Convert to DeclContext lookup...





More information about the cfe-commits mailing list