[cfe-commits] r39273 - /cfe/cfe/trunk/include/clang/Parse/Scope.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:42:18 PDT 2007


Author: sabre
Date: Wed Jul 11 11:42:18 2007
New Revision: 39273

URL: http://llvm.org/viewvc/llvm-project?rev=39273&view=rev
Log:
Switch Scope to use a SmallSet instead of a SmallVector to make isDeclScope
queries more natural.

Modified:
    cfe/cfe/trunk/include/clang/Parse/Scope.h

Modified: cfe/cfe/trunk/include/clang/Parse/Scope.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Scope.h?rev=39273&r1=39272&r2=39273&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Scope.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Scope.h Wed Jul 11 11:42:18 2007
@@ -15,7 +15,7 @@
 #define LLVM_CLANG_PARSE_SCOPE_H
 
 #include "clang/Parse/Action.h"
-#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/SmallSet.h"
 
 namespace llvm {
 namespace clang {
@@ -77,7 +77,7 @@
   /// popped, these declarations are removed from the IdentifierTable's notion
   /// of current declaration.  It is up to the current Action implementation to
   /// implement these semantics.
-  SmallVector<Action::DeclTy*, 32> DeclsInScope;
+  SmallSet<Action::DeclTy*, 32> DeclsInScope;
 public:
   Scope(Scope *Parent, unsigned ScopeFlags) {
     Init(Parent, ScopeFlags);
@@ -100,7 +100,7 @@
   }
   
   
-  typedef SmallVector<Action::DeclTy*, 32>::iterator decl_iterator;
+  typedef SmallVector<Action::DeclTy*, 32>::const_iterator decl_iterator;
   typedef SmallVector<Action::DeclTy*, 32>::const_iterator decl_const_iterator;
   
   decl_iterator decl_begin() { return DeclsInScope.begin(); }
@@ -110,18 +110,13 @@
   decl_const_iterator decl_end()   const { return DeclsInScope.end(); }
 
   void AddDecl(Action::DeclTy *D) {
-    DeclsInScope.push_back(D);
+    DeclsInScope.insert(D);
   }
   
   /// isDeclScope - Return true if this is the scope that the specified decl is
   /// declared in.
   bool isDeclScope(Action::DeclTy *D) {
-    // FIXME: this is bad.  We should use a SmallSet instead of a smallvector
-    // for DeclsInScope to handle scopes with thousands of variables!
-    for (unsigned i = 0, e = DeclsInScope.size(); i != e; ++i)
-      if (DeclsInScope[i] == D)
-        return true;
-    return false;
+    return DeclsInScope.count(D) != 0;
   }
   
   





More information about the cfe-commits mailing list