diff options
author | Owen Anderson <resistor@mac.com> | 2007-07-27 18:07:02 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2007-07-27 18:07:02 +0000 |
commit | c482655096ea252fa2e745713c42d488ba7ec1a7 (patch) | |
tree | 7c7116dbdb0c87ad5cc41af1b7bf50c0f24d5585 /include/llvm/ADT/SmallPtrSet.h | |
parent | 11821703eba67a777530c1df0d19b7590d906c97 (diff) | |
download | external_llvm-c482655096ea252fa2e745713c42d488ba7ec1a7.zip external_llvm-c482655096ea252fa2e745713c42d488ba7ec1a7.tar.gz external_llvm-c482655096ea252fa2e745713c42d488ba7ec1a7.tar.bz2 |
Allow SmallPtrSet to hold pointers to const data.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40556 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/SmallPtrSet.h')
-rw-r--r-- | include/llvm/ADT/SmallPtrSet.h | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/include/llvm/ADT/SmallPtrSet.h b/include/llvm/ADT/SmallPtrSet.h index 27c8459..e39a4fe 100644 --- a/include/llvm/ADT/SmallPtrSet.h +++ b/include/llvm/ADT/SmallPtrSet.h @@ -43,7 +43,7 @@ class SmallPtrSetImpl { protected: /// CurArray - This is the current set of buckets. If it points to /// SmallArray, then the set is in 'small mode'. - void **CurArray; + const void **CurArray; /// CurArraySize - The allocated size of CurArray, always a power of two. /// Note that CurArray points to an array that has CurArraySize+1 elements in /// it, so that the end iterator actually points to valid memory. @@ -52,7 +52,7 @@ protected: // If small, this is # elts allocated consequtively unsigned NumElements; unsigned NumTombstones; - void *SmallArray[1]; // Must be last ivar. + const void *SmallArray[1]; // Must be last ivar. // Helper to copy construct a SmallPtrSet. SmallPtrSetImpl(const SmallPtrSetImpl& that); @@ -88,7 +88,7 @@ public: /// insert - This returns true if the pointer was new to the set, false if it /// was already in the set. - bool insert(void *Ptr); + bool insert(const void * Ptr); template <typename IterT> void insert(IterT I, IterT E) { @@ -98,12 +98,12 @@ public: /// erase - If the set contains the specified pointer, remove it and return /// true, otherwise return false. - bool erase(void *Ptr); + bool erase(void * const Ptr); - bool count(void *Ptr) const { + bool count(void * const Ptr) const { if (isSmall()) { // Linear search for the item. - for (void *const *APtr = SmallArray, *const *E = SmallArray+NumElements; + for (const void *const *APtr = SmallArray, *const *E = SmallArray+NumElements; APtr != E; ++APtr) if (*APtr == Ptr) return true; @@ -117,10 +117,10 @@ public: private: bool isSmall() const { return CurArray == &SmallArray[0]; } - unsigned Hash(void *Ptr) const { + unsigned Hash(const void *Ptr) const { return ((uintptr_t)Ptr >> 4) & (CurArraySize-1); } - void * const *FindBucketFor(void *Ptr) const; + const void * const *FindBucketFor(const void *Ptr) const; /// Grow - Allocate a larger backing store for the buckets and move it over. void Grow(); @@ -134,9 +134,9 @@ protected: /// instances of SmallPtrSetIterator. class SmallPtrSetIteratorImpl { protected: - void *const *Bucket; + const void *const *Bucket; public: - SmallPtrSetIteratorImpl(void *const *BP) : Bucket(BP) { + SmallPtrSetIteratorImpl(const void *const *BP) : Bucket(BP) { AdvanceIfNotValid(); } @@ -162,12 +162,12 @@ protected: template<typename PtrTy> class SmallPtrSetIterator : public SmallPtrSetIteratorImpl { public: - SmallPtrSetIterator(void *const *BP) : SmallPtrSetIteratorImpl(BP) {} + SmallPtrSetIterator(const void *const *BP) : SmallPtrSetIteratorImpl(BP) {} // Most methods provided by baseclass. - PtrTy operator*() const { - return static_cast<PtrTy>(*Bucket); + const PtrTy operator*() const { + return static_cast<const PtrTy>(const_cast<void*>(*Bucket)); } inline SmallPtrSetIterator& operator++() { // Preincrement |