[cfe-commits] r135368 - /cfe/trunk/lib/Sema/SemaLookup.cpp

Chris Lattner sabre at nondot.org
Sun Jul 17 18:54:02 PDT 2011


Author: lattner
Date: Sun Jul 17 20:54:02 2011
New Revision: 135368

URL: http://llvm.org/viewvc/llvm-project?rev=135368&view=rev
Log:
Use the new llvm::TinyPtrVector class, which implements exactly what
ShadowMapEntry was.

Modified:
    cfe/trunk/lib/Sema/SemaLookup.cpp

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=135368&r1=135367&r2=135368&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Sun Jul 17 20:54:02 2011
@@ -35,6 +35,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/TinyPtrVector.h"
 #include "llvm/Support/ErrorHandling.h"
 #include <limits>
 #include <list>
@@ -2530,24 +2531,7 @@
   /// \brief An entry in the shadow map, which is optimized to store a
   /// single declaration (the common case) but can also store a list
   /// of declarations.
-  class ShadowMapEntry {
-    typedef llvm::SmallVector<NamedDecl *, 4> DeclVector;
-
-    /// \brief Contains either the solitary NamedDecl * or a vector
-    /// of declarations.
-    llvm::PointerUnion<NamedDecl *, DeclVector*> DeclOrVector;
-
-  public:
-    ShadowMapEntry() : DeclOrVector() { }
-
-    void Add(NamedDecl *ND);
-    void Destroy();
-
-    // Iteration.
-    typedef NamedDecl * const *iterator;
-    iterator begin();
-    iterator end();
-  };
+  typedef llvm::TinyPtrVector<NamedDecl*> ShadowMapEntry;
 
 private:
   /// \brief A mapping from declaration names to the declarations that have
@@ -2581,7 +2565,9 @@
   NamedDecl *checkHidden(NamedDecl *ND);
 
   /// \brief Add a declaration to the current shadow map.
-  void add(NamedDecl *ND) { ShadowMaps.back()[ND->getDeclName()].Add(ND); }
+  void add(NamedDecl *ND) {
+    ShadowMaps.back()[ND->getDeclName()].push_back(ND);
+  }
 };
 
 /// \brief RAII object that records when we've entered a shadow context.
@@ -2596,66 +2582,12 @@
   }
 
   ~ShadowContextRAII() {
-    for (ShadowMap::iterator E = Visible.ShadowMaps.back().begin(),
-                          EEnd = Visible.ShadowMaps.back().end();
-         E != EEnd;
-         ++E)
-      E->second.Destroy();
-
     Visible.ShadowMaps.pop_back();
   }
 };
 
 } // end anonymous namespace
 
-void VisibleDeclsRecord::ShadowMapEntry::Add(NamedDecl *ND) {
-  if (DeclOrVector.isNull()) {
-    // 0 - > 1 elements: just set the single element information.
-    DeclOrVector = ND;
-    return;
-  }
-
-  if (NamedDecl *PrevND = DeclOrVector.dyn_cast<NamedDecl *>()) {
-    // 1 -> 2 elements: create the vector of results and push in the
-    // existing declaration.
-    DeclVector *Vec = new DeclVector;
-    Vec->push_back(PrevND);
-    DeclOrVector = Vec;
-  }
-
-  // Add the new element to the end of the vector.
-  DeclOrVector.get<DeclVector*>()->push_back(ND);
-}
-
-void VisibleDeclsRecord::ShadowMapEntry::Destroy() {
-  if (DeclVector *Vec = DeclOrVector.dyn_cast<DeclVector *>()) {
-    delete Vec;
-    DeclOrVector = ((NamedDecl *)0);
-  }
-}
-
-VisibleDeclsRecord::ShadowMapEntry::iterator
-VisibleDeclsRecord::ShadowMapEntry::begin() {
-  if (DeclOrVector.isNull())
-    return 0;
-
-  if (DeclOrVector.is<NamedDecl *>())
-    return DeclOrVector.getAddrOf<NamedDecl *>();
-
-  return DeclOrVector.get<DeclVector *>()->begin();
-}
-
-VisibleDeclsRecord::ShadowMapEntry::iterator
-VisibleDeclsRecord::ShadowMapEntry::end() {
-  if (DeclOrVector.isNull())
-    return 0;
-
-  if (DeclOrVector.is<NamedDecl *>())
-    return DeclOrVector.getAddrOf<NamedDecl *>() + 1;
-
-  return DeclOrVector.get<DeclVector *>()->end();
-}
-
 NamedDecl *VisibleDeclsRecord::checkHidden(NamedDecl *ND) {
   // Look through using declarations.
   ND = ND->getUnderlyingDecl();





More information about the cfe-commits mailing list