Skip to content

Commit 8b3e345

Browse files
committed
[ADT] Clean up TinyPtrVector
- Remove implicit ArrayRef conversion, ArrayRef has conversions now. - Remove extra dyn_casts if the TinyPtrVector can only be a big vector No functionality change intended.
1 parent e8f85cf commit 8b3e345

File tree

1 file changed

+18
-46
lines changed

1 file changed

+18
-46
lines changed

llvm/include/llvm/ADT/TinyPtrVector.h

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -132,47 +132,17 @@ class TinyPtrVector {
132132
: Count == 1 ? PtrUnion(Value)
133133
: PtrUnion(new VecTy(Count, Value))) {}
134134

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-
162135
bool empty() const {
163136
// This vector can be empty if it contains no element, or if it
164137
// 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();
169141
}
170142

171143
unsigned size() const {
172-
if (empty())
173-
return 0;
174144
if (isa<EltTy>(Val))
175-
return 1;
145+
return Val.isNull() ? 0 : 1;
176146
return cast<VecTy *>(Val)->size();
177147
}
178148

@@ -214,6 +184,9 @@ class TinyPtrVector {
214184
return const_reverse_iterator(begin());
215185
}
216186

187+
EltTy *data() { return begin(); }
188+
const EltTy *data() const { return begin(); }
189+
217190
EltTy operator[](unsigned i) const {
218191
assert(!Val.isNull() && "can't index into an empty vector");
219192
if (isa<EltTy>(Val)) {
@@ -250,8 +223,8 @@ class TinyPtrVector {
250223
// If we have a single value, convert to a vector.
251224
if (isa<EltTy>(Val)) {
252225
EltTy V = cast<EltTy>(Val);
253-
Val = new VecTy();
254-
cast<VecTy *>(Val)->push_back(V);
226+
Val = new VecTy({V, NewVal});
227+
return;
255228
}
256229

257230
// Add the new value, we know we have a vector.
@@ -261,20 +234,19 @@ class TinyPtrVector {
261234
void pop_back() {
262235
// If we have a single value, convert to empty.
263236
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();
267240
}
268241

269242
void clear() {
270243
// If we have a single value, convert to empty.
271244
if (isa<EltTy>(Val)) {
272245
Val = EltTy();
273-
} else if (VecTy *Vec = dyn_cast_if_present<VecTy *>(Val)) {
246+
} else {
274247
// If we have a vector form, just clear it.
275-
Vec->clear();
248+
cast<VecTy *>(Val)->clear();
276249
}
277-
// Otherwise, we're already empty.
278250
}
279251

280252
iterator erase(iterator I) {
@@ -285,10 +257,10 @@ class TinyPtrVector {
285257
if (isa<EltTy>(Val)) {
286258
if (I == begin())
287259
Val = EltTy();
288-
} else if (VecTy *Vec = dyn_cast_if_present<VecTy *>(Val)) {
260+
} else {
289261
// multiple items in a vector; just do the erase, there is no
290262
// benefit to collapsing back to a pointer
291-
return Vec->erase(I);
263+
return cast<VecTy *>(Val)->erase(I);
292264
}
293265
return end();
294266
}
@@ -301,8 +273,8 @@ class TinyPtrVector {
301273
if (isa<EltTy>(Val)) {
302274
if (S == begin() && S != E)
303275
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);
306278
}
307279
return end();
308280
}

0 commit comments

Comments
 (0)