llvm.org GIT mirror llvm / 373a733
make smallptrset more const and type correct, which caught a few minor bugs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43782 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
2 changed file(s) with 32 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
9090 NumTombstones = 0;
9191 }
9292
93 /// insert - This returns true if the pointer was new to the set, false if it
94 /// was already in the set.
95 bool insert(const void * Ptr);
96
97 template
98 void insert(IterT I, IterT E) {
99 for (; I != E; ++I)
100 insert((void*)*I);
101 }
102
103 /// erase - If the set contains the specified pointer, remove it and return
104 /// true, otherwise return false.
105 bool erase(const void * Ptr);
106
107 bool count(const void * Ptr) const {
93 protected:
94 /// insert_imp - This returns true if the pointer was new to the set, false if
95 /// it was already in the set. This is hidden from the client so that the
96 /// derived class can check that the right type of pointer is passed in.
97 bool insert_imp(const void * Ptr);
98
99 /// erase_imp - If the set contains the specified pointer, remove it and
100 /// return true, otherwise return false. This is hidden from the client so
101 /// that the derived class can check that the right type of pointer is passed
102 /// in.
103 bool erase_imp(const void * Ptr);
104
105 bool count_imp(const void * Ptr) const {
108106 if (isSmall()) {
109107 // Linear search for the item.
110108 for (const void *const *APtr = SmallArray,
231229 insert(I, E);
232230 }
233231
232 /// insert - This returns true if the pointer was new to the set, false if it
233 /// was already in the set.
234 bool insert(PtrType Ptr) { return insert_imp(Ptr); }
235
236 /// erase - If the set contains the specified pointer, remove it and return
237 /// true, otherwise return false.
238 bool erase(PtrType Ptr) { return erase_imp(Ptr); }
239
240 /// count - Return true if the specified pointer is in the set.
241 bool count(PtrType Ptr) const { return count_imp(Ptr); }
242
243 template
244 void insert(IterT I, IterT E) {
245 for (; I != E; ++I)
246 insert(*I);
247 }
248
234249 typedef SmallPtrSetIterator iterator;
235250 typedef SmallPtrSetIterator const_iterator;
236251 inline iterator begin() const {
3535 CurArray[CurArraySize] = 0;
3636 }
3737
38 bool SmallPtrSetImpl::insert(const void * Ptr) {
38 bool SmallPtrSetImpl::insert_imp(const void * Ptr) {
3939 if (isSmall()) {
4040 // Check to see if it is already in the set.
4141 for (const void **APtr = SmallArray, **E = SmallArray+NumElements;
6868 return true;
6969 }
7070
71 bool SmallPtrSetImpl::erase(const void * Ptr) {
71 bool SmallPtrSetImpl::erase_imp(const void * Ptr) {
7272 if (isSmall()) {
7373 // Check to see if it is in the set.
7474 for (const void **APtr = SmallArray, **E = SmallArray+NumElements;