@@ -139,10 +139,6 @@ class SmallSet {
139
139
SmallVector<T, N> Vector;
140
140
std::set<T, C> Set;
141
141
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
142
// In small mode SmallPtrSet uses linear search for the elements, so it is
147
143
// not a good idea to choose this value too high. You may consider using a
148
144
// DenseSet<> instead if you expect many elements in the set.
@@ -163,13 +159,7 @@ class SmallSet {
163
159
}
164
160
165
161
// / 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
- }
162
+ size_type count (const T &V) const { return contains (V) ? 1 : 0 ; }
173
163
174
164
// / insert - Insert an element into the set if it isn't already there.
175
165
// / Returns a pair. The first value of it is an iterator to the inserted
@@ -181,7 +171,7 @@ class SmallSet {
181
171
return std::make_pair (const_iterator (I), Inserted);
182
172
}
183
173
184
- VIterator I = vfind ( V);
174
+ auto I = llvm::find (Vector, V);
185
175
if (I != Vector.end ()) // Don't reinsert if it already exists.
186
176
return std::make_pair (const_iterator (I), false );
187
177
if (Vector.size () < N) {
@@ -206,11 +196,12 @@ class SmallSet {
206
196
bool erase (const T &V) {
207
197
if (!isSmall ())
208
198
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
- }
199
+
200
+ auto It = llvm::find (Vector, V);
201
+ if (It != Vector.end ()) {
202
+ Vector.erase (It);
203
+ return true ;
204
+ }
214
205
return false ;
215
206
}
216
207
@@ -234,19 +225,12 @@ class SmallSet {
234
225
// / Check if the SmallSet contains the given element.
235
226
bool contains (const T &V) const {
236
227
if (isSmall ())
237
- return vfind (V) != Vector. end ( );
238
- return Set. find (V) != Set. end ( );
228
+ return llvm::is_contained ( Vector, V );
229
+ return llvm::is_contained ( Set, V );
239
230
}
240
231
241
232
private:
242
233
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
234
};
251
235
252
236
// / If this set is of pointer values, transparently switch over to using
0 commit comments