16
16
17
17
#include " llvm/ADT/SmallPtrSet.h"
18
18
#include " llvm/ADT/SmallVector.h"
19
- #include " llvm/ADT/STLExtras.h"
20
19
#include " llvm/ADT/iterator.h"
21
- #include " llvm/Support/Compiler.h"
22
- #include " llvm/Support/type_traits.h"
23
20
#include < cstddef>
24
21
#include < functional>
25
22
#include < set>
26
- #include < type_traits>
27
23
#include < utility>
28
24
29
25
namespace llvm {
@@ -139,10 +135,6 @@ class SmallSet {
139
135
SmallVector<T, N> Vector;
140
136
std::set<T, C> Set;
141
137
142
- using VIterator = typename SmallVector<T, N>::const_iterator;
143
- using SIterator = typename std::set<T, C>::const_iterator;
144
- using mutable_iterator = typename SmallVector<T, N>::iterator;
145
-
146
138
// In small mode SmallPtrSet uses linear search for the elements, so it is
147
139
// not a good idea to choose this value too high. You may consider using a
148
140
// DenseSet<> instead if you expect many elements in the set.
@@ -163,13 +155,7 @@ class SmallSet {
163
155
}
164
156
165
157
// / count - Return 1 if the element is in the set, 0 otherwise.
166
- size_type count (const T &V) const {
167
- if (isSmall ()) {
168
- // Since the collection is small, just do a linear search.
169
- return vfind (V) == Vector.end () ? 0 : 1 ;
170
- }
171
- return Set.count (V);
172
- }
158
+ size_type count (const T &V) const { return contains (V) ? 1 : 0 ; }
173
159
174
160
// / insert - Insert an element into the set if it isn't already there.
175
161
// / Returns a pair. The first value of it is an iterator to the inserted
@@ -181,7 +167,7 @@ class SmallSet {
181
167
return std::make_pair (const_iterator (I), Inserted);
182
168
}
183
169
184
- VIterator I = vfind ( V);
170
+ auto I = std::find (Vector. begin (), Vector. end (), V);
185
171
if (I != Vector.end ()) // Don't reinsert if it already exists.
186
172
return std::make_pair (const_iterator (I), false );
187
173
if (Vector.size () < N) {
@@ -206,11 +192,11 @@ class SmallSet {
206
192
bool erase (const T &V) {
207
193
if (!isSmall ())
208
194
return Set.erase (V);
209
- for (mutable_iterator I = Vector.begin (), E = Vector.end (); I != E; ++I)
210
- if (*I == V ) {
211
- Vector.erase (I);
212
- return true ;
213
- }
195
+ auto I = std::find ( Vector.begin (), Vector.end (), V);
196
+ if (I != Vector. end () ) {
197
+ Vector.erase (I);
198
+ return true ;
199
+ }
214
200
return false ;
215
201
}
216
202
@@ -234,19 +220,12 @@ class SmallSet {
234
220
// / Check if the SmallSet contains the given element.
235
221
bool contains (const T &V) const {
236
222
if (isSmall ())
237
- return vfind ( V) != Vector.end ();
223
+ return std::find (Vector. begin (), Vector. end (), V) != Vector.end ();
238
224
return Set.find (V) != Set.end ();
239
225
}
240
226
241
227
private:
242
228
bool isSmall () const { return Set.empty (); }
243
-
244
- VIterator vfind (const T &V) const {
245
- for (VIterator I = Vector.begin (), E = Vector.end (); I != E; ++I)
246
- if (*I == V)
247
- return I;
248
- return Vector.end ();
249
- }
250
229
};
251
230
252
231
// / If this set is of pointer values, transparently switch over to using
0 commit comments