X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FTinyPtrVector.h;h=ca624c6c5412bc0f047b044a61720bb641a2b6f1;hb=40dab1059e72d3af59f2523fa8a7d05f40dafca5;hp=362f2961ec306ce1ab2fed4145664748608a7316;hpb=bb07f21c76f011d8dde491104ff242af30bfb4ab;p=oota-llvm.git diff --git a/include/llvm/ADT/TinyPtrVector.h b/include/llvm/ADT/TinyPtrVector.h index 362f2961ec3..ca624c6c541 100644 --- a/include/llvm/ADT/TinyPtrVector.h +++ b/include/llvm/ADT/TinyPtrVector.h @@ -10,8 +10,10 @@ #ifndef LLVM_ADT_TINYPTRVECTOR_H #define LLVM_ADT_TINYPTRVECTOR_H +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/PointerUnion.h" +#include "llvm/Support/Compiler.h" namespace llvm { @@ -25,6 +27,8 @@ template class TinyPtrVector { public: typedef llvm::SmallVector VecTy; + typedef typename VecTy::value_type value_type; + llvm::PointerUnion Val; TinyPtrVector() {} @@ -32,6 +36,11 @@ public: if (VecTy *V = Val.template dyn_cast()) Val = new VecTy(*V); } +#if LLVM_USE_RVALUE_REFERENCES + TinyPtrVector(TinyPtrVector &&RHS) : Val(RHS.Val) { + RHS.Val = (EltTy)0; + } +#endif ~TinyPtrVector() { if (VecTy *V = Val.template dyn_cast()) delete V; @@ -42,7 +51,7 @@ public: if (Val.isNull()) return ArrayRef(); if (Val.template is()) - return *Val.template getAddrOf(); + return *Val.getAddrOfPtr1(); return *Val.template get(); } @@ -63,13 +72,10 @@ public: return Val.template get()->size(); } - typedef const EltTy *const const_iterator; + typedef const EltTy *const_iterator; typedef EltTy *iterator; iterator begin() { - if (empty()) - return 0; - if (Val.template is()) return Val.getAddrOfPtr1(); @@ -77,11 +83,8 @@ public: } iterator end() { - if (empty()) - return 0; - if (Val.template is()) - return begin() + 1; + return begin() + (Val.isNull() ? 0 : 1); return Val.template get()->end(); } @@ -113,6 +116,14 @@ public: return Val.template get()->front(); } + EltTy back() const { + assert(!empty() && "vector empty"); + if (EltTy V = Val.template dyn_cast()) + return V; + return Val.template get()->back(); + } + + void push_back(EltTy NewVal) { assert(NewVal != 0 && "Can't add a null value"); @@ -132,6 +143,15 @@ public: Val.template get()->push_back(NewVal); } + void pop_back() { + // If we have a single value, convert to empty. + if (Val.template is()) + Val = (EltTy)0; + else if (VecTy *Vec = Val.template get()) + Vec->pop_back(); + } + + void clear() { // If we have a single value, convert to empty. if (Val.template is()) { @@ -153,12 +173,14 @@ public: // benefit to collapsing back to a pointer return Vec->erase(I); } - - return 0; + return end(); } private: void operator=(const TinyPtrVector&); // NOT IMPLEMENTED YET. +#if LLVM_USE_RVALUE_REFERENCES + void operator=(TinyPtrVector&&); // NOT IMPLEMENTED YET. +#endif }; } // end namespace llvm