[llvm] r200687 - Rename the non-templated base class of SmallPtrSet to

Chandler Carruth chandlerc at gmail.com
Mon Feb 3 03:24:18 PST 2014


Author: chandlerc
Date: Mon Feb  3 05:24:18 2014
New Revision: 200687

URL: http://llvm.org/viewvc/llvm-project?rev=200687&view=rev
Log:
Rename the non-templated base class of SmallPtrSet to
'SmallPtrSetImplBase'. This more closely matches the organization of
SmallVector and should allow introducing a SmallPtrSetImpl which serves
the same purpose as SmallVectorImpl: isolating the element type from the
particular small size chosen. This in turn allows a lot of
simplification of APIs by not coding them against a specific small size
which is rarely needed.

Modified:
    llvm/trunk/include/llvm/ADT/SmallPtrSet.h
    llvm/trunk/lib/Support/SmallPtrSet.cpp

Modified: llvm/trunk/include/llvm/ADT/SmallPtrSet.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallPtrSet.h?rev=200687&r1=200686&r2=200687&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SmallPtrSet.h (original)
+++ llvm/trunk/include/llvm/ADT/SmallPtrSet.h Mon Feb  3 05:24:18 2014
@@ -8,7 +8,7 @@
 //===----------------------------------------------------------------------===//
 //
 // This file defines the SmallPtrSet class.  See the doxygen comment for
-// SmallPtrSetImpl for more details on the algorithm used.
+// SmallPtrSetImplBase for more details on the algorithm used.
 //
 //===----------------------------------------------------------------------===//
 
@@ -27,7 +27,7 @@ namespace llvm {
 
 class SmallPtrSetIteratorImpl;
 
-/// SmallPtrSetImpl - This is the common code shared among all the
+/// SmallPtrSetImplBase - This is the common code shared among all the
 /// SmallPtrSet<>'s, which is almost everything.  SmallPtrSet has two modes, one
 /// for small and one for large sets.
 ///
@@ -45,7 +45,7 @@ class SmallPtrSetIteratorImpl;
 /// (-2), to allow deletion.  The hash table is resized when the table is 3/4 or
 /// more.  When this happens, the table is doubled in size.
 ///
-class SmallPtrSetImpl {
+class SmallPtrSetImplBase {
   friend class SmallPtrSetIteratorImpl;
 protected:
   /// SmallArray - Points to a fixed size set of buckets, used in 'small mode'.
@@ -61,18 +61,18 @@ protected:
   unsigned NumTombstones;
 
   // Helpers to copy and move construct a SmallPtrSet.
-  SmallPtrSetImpl(const void **SmallStorage, const SmallPtrSetImpl &that);
+  SmallPtrSetImplBase(const void **SmallStorage, const SmallPtrSetImplBase &that);
 #if LLVM_HAS_RVALUE_REFERENCES
-  SmallPtrSetImpl(const void **SmallStorage, unsigned SmallSize,
-                  SmallPtrSetImpl &&that);
+  SmallPtrSetImplBase(const void **SmallStorage, unsigned SmallSize,
+                  SmallPtrSetImplBase &&that);
 #endif
-  explicit SmallPtrSetImpl(const void **SmallStorage, unsigned SmallSize) :
+  explicit SmallPtrSetImplBase(const void **SmallStorage, unsigned SmallSize) :
     SmallArray(SmallStorage), CurArray(SmallStorage), CurArraySize(SmallSize) {
     assert(SmallSize && (SmallSize & (SmallSize-1)) == 0 &&
            "Initial size must be a power of two!");
     clear();
   }
-  ~SmallPtrSetImpl();
+  ~SmallPtrSetImplBase();
 
 public:
   bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const { return size() == 0; }
@@ -132,15 +132,15 @@ private:
   /// Grow - Allocate a larger backing store for the buckets and move it over.
   void Grow(unsigned NewSize);
 
-  void operator=(const SmallPtrSetImpl &RHS) LLVM_DELETED_FUNCTION;
+  void operator=(const SmallPtrSetImplBase &RHS) LLVM_DELETED_FUNCTION;
 protected:
   /// swap - Swaps the elements of two sets.
   /// Note: This method assumes that both sets have the same small size.
-  void swap(SmallPtrSetImpl &RHS);
+  void swap(SmallPtrSetImplBase &RHS);
 
-  void CopyFrom(const SmallPtrSetImpl &RHS);
+  void CopyFrom(const SmallPtrSetImplBase &RHS);
 #if LLVM_HAS_RVALUE_REFERENCES
-  void MoveFrom(unsigned SmallSize, SmallPtrSetImpl &&RHS);
+  void MoveFrom(unsigned SmallSize, SmallPtrSetImplBase &&RHS);
 #endif
 };
 
@@ -170,8 +170,8 @@ protected:
   void AdvanceIfNotValid() {
     assert(Bucket <= End);
     while (Bucket != End &&
-           (*Bucket == SmallPtrSetImpl::getEmptyMarker() ||
-            *Bucket == SmallPtrSetImpl::getTombstoneMarker()))
+           (*Bucket == SmallPtrSetImplBase::getEmptyMarker() ||
+            *Bucket == SmallPtrSetImplBase::getTombstoneMarker()))
       ++Bucket;
   }
 };
@@ -238,24 +238,24 @@ struct RoundUpToPowerOfTwo {
 /// SmallPtrSet - This class implements a set which is optimized for holding
 /// SmallSize or less elements.  This internally rounds up SmallSize to the next
 /// power of two if it is not already a power of two.  See the comments above
-/// SmallPtrSetImpl for details of the algorithm.
+/// SmallPtrSetImplBase for details of the algorithm.
 template<class PtrType, unsigned SmallSize>
-class SmallPtrSet : public SmallPtrSetImpl {
+class SmallPtrSet : public SmallPtrSetImplBase {
   // Make sure that SmallSize is a power of two, round up if not.
   enum { SmallSizePowTwo = RoundUpToPowerOfTwo<SmallSize>::Val };
   /// SmallStorage - Fixed size storage used in 'small mode'.
   const void *SmallStorage[SmallSizePowTwo];
   typedef PointerLikeTypeTraits<PtrType> PtrTraits;
 public:
-  SmallPtrSet() : SmallPtrSetImpl(SmallStorage, SmallSizePowTwo) {}
-  SmallPtrSet(const SmallPtrSet &that) : SmallPtrSetImpl(SmallStorage, that) {}
+  SmallPtrSet() : SmallPtrSetImplBase(SmallStorage, SmallSizePowTwo) {}
+  SmallPtrSet(const SmallPtrSet &that) : SmallPtrSetImplBase(SmallStorage, that) {}
 #if LLVM_HAS_RVALUE_REFERENCES
   SmallPtrSet(SmallPtrSet &&that)
-      : SmallPtrSetImpl(SmallStorage, SmallSizePowTwo, std::move(that)) {}
+      : SmallPtrSetImplBase(SmallStorage, SmallSizePowTwo, std::move(that)) {}
 #endif
 
   template<typename It>
-  SmallPtrSet(It I, It E) : SmallPtrSetImpl(SmallStorage, SmallSizePowTwo) {
+  SmallPtrSet(It I, It E) : SmallPtrSetImplBase(SmallStorage, SmallSizePowTwo) {
     insert(I, E);
   }
 
@@ -309,7 +309,7 @@ public:
 
   /// swap - Swaps the elements of two sets.
   void swap(SmallPtrSet<PtrType, SmallSize> &RHS) {
-    SmallPtrSetImpl::swap(RHS);
+    SmallPtrSetImplBase::swap(RHS);
   }
 };
 

Modified: llvm/trunk/lib/Support/SmallPtrSet.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SmallPtrSet.cpp?rev=200687&r1=200686&r2=200687&view=diff
==============================================================================
--- llvm/trunk/lib/Support/SmallPtrSet.cpp (original)
+++ llvm/trunk/lib/Support/SmallPtrSet.cpp Mon Feb  3 05:24:18 2014
@@ -20,7 +20,7 @@
 
 using namespace llvm;
 
-void SmallPtrSetImpl::shrink_and_clear() {
+void SmallPtrSetImplBase::shrink_and_clear() {
   assert(!isSmall() && "Can't shrink a small set!");
   free(CurArray);
 
@@ -34,7 +34,7 @@ void SmallPtrSetImpl::shrink_and_clear()
   memset(CurArray, -1, CurArraySize*sizeof(void*));
 }
 
-bool SmallPtrSetImpl::insert_imp(const void * Ptr) {
+bool SmallPtrSetImplBase::insert_imp(const void * Ptr) {
   if (isSmall()) {
     // Check to see if it is already in the set.
     for (const void **APtr = SmallArray, **E = SmallArray+NumElements;
@@ -71,7 +71,7 @@ bool SmallPtrSetImpl::insert_imp(const v
   return true;
 }
 
-bool SmallPtrSetImpl::erase_imp(const void * Ptr) {
+bool SmallPtrSetImplBase::erase_imp(const void * Ptr) {
   if (isSmall()) {
     // Check to see if it is in the set.
     for (const void **APtr = SmallArray, **E = SmallArray+NumElements;
@@ -98,7 +98,7 @@ bool SmallPtrSetImpl::erase_imp(const vo
   return true;
 }
 
-const void * const *SmallPtrSetImpl::FindBucketFor(const void *Ptr) const {
+const void * const *SmallPtrSetImplBase::FindBucketFor(const void *Ptr) const {
   unsigned Bucket = DenseMapInfo<void *>::getHashValue(Ptr) & (CurArraySize-1);
   unsigned ArraySize = CurArraySize;
   unsigned ProbeAmt = 1;
@@ -127,7 +127,7 @@ const void * const *SmallPtrSetImpl::Fin
 
 /// Grow - Allocate a larger backing store for the buckets and move it over.
 ///
-void SmallPtrSetImpl::Grow(unsigned NewSize) {
+void SmallPtrSetImplBase::Grow(unsigned NewSize) {
   // Allocate at twice as many buckets, but at least 128.
   unsigned OldSize = CurArraySize;
   
@@ -163,8 +163,8 @@ void SmallPtrSetImpl::Grow(unsigned NewS
   }
 }
 
-SmallPtrSetImpl::SmallPtrSetImpl(const void **SmallStorage,
-                                 const SmallPtrSetImpl& that) {
+SmallPtrSetImplBase::SmallPtrSetImplBase(const void **SmallStorage,
+                                 const SmallPtrSetImplBase& that) {
   SmallArray = SmallStorage;
 
   // If we're becoming small, prepare to insert into our stack space
@@ -187,8 +187,9 @@ SmallPtrSetImpl::SmallPtrSetImpl(const v
 }
 
 #if LLVM_HAS_RVALUE_REFERENCES
-SmallPtrSetImpl::SmallPtrSetImpl(const void **SmallStorage, unsigned SmallSize,
-                                 SmallPtrSetImpl &&that) {
+SmallPtrSetImplBase::SmallPtrSetImplBase(const void **SmallStorage,
+                                         unsigned SmallSize,
+                                         SmallPtrSetImplBase &&that) {
   SmallArray = SmallStorage;
 
   // Copy over the basic members.
@@ -217,7 +218,7 @@ SmallPtrSetImpl::SmallPtrSetImpl(const v
 
 /// CopyFrom - implement operator= from a smallptrset that has the same pointer
 /// type, but may have a different small size.
-void SmallPtrSetImpl::CopyFrom(const SmallPtrSetImpl &RHS) {
+void SmallPtrSetImplBase::CopyFrom(const SmallPtrSetImplBase &RHS) {
   assert(&RHS != this && "Self-copy should be handled by the caller.");
 
   if (isSmall() && RHS.isSmall())
@@ -254,7 +255,8 @@ void SmallPtrSetImpl::CopyFrom(const Sma
 }
 
 #if LLVM_HAS_RVALUE_REFERENCES
-void SmallPtrSetImpl::MoveFrom(unsigned SmallSize, SmallPtrSetImpl &&RHS) {
+void SmallPtrSetImplBase::MoveFrom(unsigned SmallSize,
+                                   SmallPtrSetImplBase &&RHS) {
   assert(&RHS != this && "Self-move should be handled by the caller.");
 
   if (!isSmall())
@@ -282,7 +284,7 @@ void SmallPtrSetImpl::MoveFrom(unsigned
 }
 #endif
 
-void SmallPtrSetImpl::swap(SmallPtrSetImpl &RHS) {
+void SmallPtrSetImplBase::swap(SmallPtrSetImplBase &RHS) {
   if (this == &RHS) return;
 
   // We can only avoid copying elements if neither set is small.
@@ -332,7 +334,7 @@ void SmallPtrSetImpl::swap(SmallPtrSetIm
   std::swap(this->NumElements, RHS.NumElements);
 }
 
-SmallPtrSetImpl::~SmallPtrSetImpl() {
+SmallPtrSetImplBase::~SmallPtrSetImplBase() {
   if (!isSmall())
     free(CurArray);
 }





More information about the llvm-commits mailing list