Author: lattner Date: Tue Nov 6 16:12:43 2007 New Revision: 43782 URL: http://llvm.org/viewvc/llvm-project?rev=43782&view=rev Log: make smallptrset more const and type correct, which caught a few minor bugs.
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=43782&r1=43781&r2=43782&view=diff ============================================================================== --- llvm/trunk/include/llvm/ADT/SmallPtrSet.h (original) +++ llvm/trunk/include/llvm/ADT/SmallPtrSet.h Tue Nov 6 16:12:43 2007 @@ -91,21 +91,19 @@ NumTombstones = 0; } - /// insert - This returns true if the pointer was new to the set, false if it - /// was already in the set. - bool insert(const void * Ptr); - - template <typename IterT> - void insert(IterT I, IterT E) { - for (; I != E; ++I) - insert((void*)*I); - } - - /// erase - If the set contains the specified pointer, remove it and return - /// true, otherwise return false. - bool erase(const void * Ptr); +protected: + /// insert_imp - This returns true if the pointer was new to the set, false if + /// it was already in the set. This is hidden from the client so that the + /// derived class can check that the right type of pointer is passed in. + bool insert_imp(const void * Ptr); + + /// erase_imp - If the set contains the specified pointer, remove it and + /// return true, otherwise return false. This is hidden from the client so + /// that the derived class can check that the right type of pointer is passed + /// in. + bool erase_imp(const void * Ptr); - bool count(const void * Ptr) const { + bool count_imp(const void * Ptr) const { if (isSmall()) { // Linear search for the item. for (const void *const *APtr = SmallArray, @@ -232,6 +230,23 @@ insert(I, E); } + /// insert - This returns true if the pointer was new to the set, false if it + /// was already in the set. + bool insert(PtrType Ptr) { return insert_imp(Ptr); } + + /// erase - If the set contains the specified pointer, remove it and return + /// true, otherwise return false. + bool erase(PtrType Ptr) { return erase_imp(Ptr); } + + /// count - Return true if the specified pointer is in the set. + bool count(PtrType Ptr) const { return count_imp(Ptr); } + + template <typename IterT> + void insert(IterT I, IterT E) { + for (; I != E; ++I) + insert(*I); + } + typedef SmallPtrSetIterator<PtrType> iterator; typedef SmallPtrSetIterator<PtrType> const_iterator; inline iterator begin() const { Modified: llvm/trunk/lib/Support/SmallPtrSet.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SmallPtrSet.cpp?rev=43782&r1=43781&r2=43782&view=diff ============================================================================== --- llvm/trunk/lib/Support/SmallPtrSet.cpp (original) +++ llvm/trunk/lib/Support/SmallPtrSet.cpp Tue Nov 6 16:12:43 2007 @@ -36,7 +36,7 @@ CurArray[CurArraySize] = 0; } -bool SmallPtrSetImpl::insert(const void * Ptr) { +bool SmallPtrSetImpl::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; @@ -69,7 +69,7 @@ return true; } -bool SmallPtrSetImpl::erase(const void * Ptr) { +bool SmallPtrSetImpl::erase_imp(const void * Ptr) { if (isSmall()) { // Check to see if it is in the set. for (const void **APtr = SmallArray, **E = SmallArray+NumElements; _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits