@@ -132,47 +132,17 @@ class TinyPtrVector {
132
132
: Count == 1 ? PtrUnion(Value)
133
133
: PtrUnion(new VecTy(Count, Value))) {}
134
134
135
- // implicit conversion operator to ArrayRef.
136
- operator ArrayRef<EltTy>() const {
137
- if (Val.isNull ())
138
- return {};
139
- if (isa<EltTy>(Val))
140
- return *Val.getAddrOfPtr1 ();
141
- return *cast<VecTy *>(Val);
142
- }
143
-
144
- // implicit conversion operator to MutableArrayRef.
145
- operator MutableArrayRef<EltTy>() {
146
- if (Val.isNull ())
147
- return {};
148
- if (isa<EltTy>(Val))
149
- return *Val.getAddrOfPtr1 ();
150
- return *cast<VecTy *>(Val);
151
- }
152
-
153
- // Implicit conversion to ArrayRef<U> if EltTy* implicitly converts to U*.
154
- template <
155
- typename U,
156
- std::enable_if_t <std::is_convertible<ArrayRef<EltTy>, ArrayRef<U>>::value,
157
- bool > = false >
158
- operator ArrayRef<U>() const {
159
- return operator ArrayRef<EltTy>();
160
- }
161
-
162
135
bool empty () const {
163
136
// This vector can be empty if it contains no element, or if it
164
137
// contains a pointer to an empty vector.
165
- if (Val.isNull ()) return true ;
166
- if (VecTy *Vec = dyn_cast_if_present<VecTy *>(Val))
167
- return Vec->empty ();
168
- return false ;
138
+ if (isa<EltTy>(Val))
139
+ return Val.isNull ();
140
+ return cast<VecTy *>(Val)->empty ();
169
141
}
170
142
171
143
unsigned size () const {
172
- if (empty ())
173
- return 0 ;
174
144
if (isa<EltTy>(Val))
175
- return 1 ;
145
+ return Val. isNull () ? 0 : 1 ;
176
146
return cast<VecTy *>(Val)->size ();
177
147
}
178
148
@@ -214,6 +184,9 @@ class TinyPtrVector {
214
184
return const_reverse_iterator (begin ());
215
185
}
216
186
187
+ EltTy *data () { return begin (); }
188
+ const EltTy *data () const { return begin (); }
189
+
217
190
EltTy operator [](unsigned i) const {
218
191
assert (!Val.isNull () && " can't index into an empty vector" );
219
192
if (isa<EltTy>(Val)) {
@@ -250,8 +223,8 @@ class TinyPtrVector {
250
223
// If we have a single value, convert to a vector.
251
224
if (isa<EltTy>(Val)) {
252
225
EltTy V = cast<EltTy>(Val);
253
- Val = new VecTy ();
254
- cast<VecTy *>(Val)-> push_back (V) ;
226
+ Val = new VecTy ({V, NewVal} );
227
+ return ;
255
228
}
256
229
257
230
// Add the new value, we know we have a vector.
@@ -261,20 +234,19 @@ class TinyPtrVector {
261
234
void pop_back () {
262
235
// If we have a single value, convert to empty.
263
236
if (isa<EltTy>(Val))
264
- Val = ( EltTy) nullptr ;
265
- else if (VecTy *Vec = cast<VecTy *>(Val))
266
- Vec ->pop_back ();
237
+ Val = EltTy () ;
238
+ else
239
+ cast<VecTy *>(Val) ->pop_back ();
267
240
}
268
241
269
242
void clear () {
270
243
// If we have a single value, convert to empty.
271
244
if (isa<EltTy>(Val)) {
272
245
Val = EltTy ();
273
- } else if (VecTy *Vec = dyn_cast_if_present<VecTy *>(Val)) {
246
+ } else {
274
247
// If we have a vector form, just clear it.
275
- Vec ->clear ();
248
+ cast<VecTy *>(Val) ->clear ();
276
249
}
277
- // Otherwise, we're already empty.
278
250
}
279
251
280
252
iterator erase (iterator I) {
@@ -285,10 +257,10 @@ class TinyPtrVector {
285
257
if (isa<EltTy>(Val)) {
286
258
if (I == begin ())
287
259
Val = EltTy ();
288
- } else if (VecTy *Vec = dyn_cast_if_present<VecTy *>(Val)) {
260
+ } else {
289
261
// multiple items in a vector; just do the erase, there is no
290
262
// benefit to collapsing back to a pointer
291
- return Vec ->erase (I);
263
+ return cast<VecTy *>(Val) ->erase (I);
292
264
}
293
265
return end ();
294
266
}
@@ -301,8 +273,8 @@ class TinyPtrVector {
301
273
if (isa<EltTy>(Val)) {
302
274
if (S == begin () && S != E)
303
275
Val = EltTy ();
304
- } else if (VecTy *Vec = dyn_cast_if_present<VecTy *>(Val)) {
305
- return Vec ->erase (S, E);
276
+ } else {
277
+ return cast<VecTy *>(Val) ->erase (S, E);
306
278
}
307
279
return end ();
308
280
}
0 commit comments