#include "llvm/ADT/SmallVector.h"
namespace llvm {
-
+
/// TinyPtrVector - This class is specialized for cases where there are
/// normally 0 or 1 element in a vector, but is general enough to go beyond that
/// when required.
public:
typedef llvm::SmallVector<EltTy, 4> VecTy;
typedef typename VecTy::value_type value_type;
+ typedef llvm::PointerUnion<EltTy, VecTy *> PtrUnion;
- llvm::PointerUnion<EltTy, VecTy*> Val;
+private:
+ PtrUnion Val;
+public:
TinyPtrVector() {}
~TinyPtrVector() {
if (VecTy *V = Val.template dyn_cast<VecTy*>())
}
TinyPtrVector(TinyPtrVector &&RHS) : Val(RHS.Val) {
- RHS.Val = (EltTy)0;
+ RHS.Val = (EltTy)nullptr;
}
TinyPtrVector &operator=(TinyPtrVector &&RHS) {
if (this == &RHS)
}
Val = RHS.Val;
- RHS.Val = (EltTy)0;
+ RHS.Val = (EltTy)nullptr;
return *this;
}
+ /// Constructor from an ArrayRef.
+ ///
+ /// This also is a constructor for individual array elements due to the single
+ /// element constructor for ArrayRef.
+ explicit TinyPtrVector(ArrayRef<EltTy> Elts)
+ : Val(Elts.size() == 1 ? PtrUnion(Elts[0])
+ : PtrUnion(new VecTy(Elts.begin(), Elts.end()))) {}
+
// implicit conversion operator to ArrayRef.
operator ArrayRef<EltTy>() const {
if (Val.isNull())
- return ArrayRef<EltTy>();
+ return None;
+ if (Val.template is<EltTy>())
+ return *Val.getAddrOfPtr1();
+ return *Val.template get<VecTy*>();
+ }
+
+ // implicit conversion operator to MutableArrayRef.
+ operator MutableArrayRef<EltTy>() {
+ if (Val.isNull())
+ return None;
if (Val.template is<EltTy>())
return *Val.getAddrOfPtr1();
return *Val.template get<VecTy*>();
return Val.getAddrOfPtr1();
return Val.template get<VecTy *>()->begin();
-
}
iterator end() {
if (Val.template is<EltTy>())
}
void push_back(EltTy NewVal) {
- assert(NewVal != 0 && "Can't add a null value");
+ assert(NewVal && "Can't add a null value");
// If we have nothing, add something.
if (Val.isNull()) {
void pop_back() {
// If we have a single value, convert to empty.
if (Val.template is<EltTy>())
- Val = (EltTy)0;
+ Val = (EltTy)nullptr;
else if (VecTy *Vec = Val.template get<VecTy*>())
Vec->pop_back();
}
void clear() {
// If we have a single value, convert to empty.
if (Val.template is<EltTy>()) {
- Val = (EltTy)0;
+ Val = (EltTy)nullptr;
} else if (VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
// If we have a vector form, just clear it.
Vec->clear();
// If we have a single value, convert to empty.
if (Val.template is<EltTy>()) {
if (I == begin())
- Val = (EltTy)0;
+ Val = (EltTy)nullptr;
} else if (VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
// multiple items in a vector; just do the erase, there is no
// benefit to collapsing back to a pointer
if (Val.template is<EltTy>()) {
if (S == begin() && S != E)
- Val = (EltTy)0;
+ Val = (EltTy)nullptr;
} else if (VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
return Vec->erase(S, E);
}