X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FTinyPtrVector.h;h=ca624c6c5412bc0f047b044a61720bb641a2b6f1;hb=40dab1059e72d3af59f2523fa8a7d05f40dafca5;hp=f9b7d559c39efa6e49af0ad2914ac778533b05a6;hpb=ac5802bca0285eee49c1c372846552823d819181;p=oota-llvm.git diff --git a/include/llvm/ADT/TinyPtrVector.h b/include/llvm/ADT/TinyPtrVector.h index f9b7d559c39..ca624c6c541 100644 --- a/include/llvm/ADT/TinyPtrVector.h +++ b/include/llvm/ADT/TinyPtrVector.h @@ -27,6 +27,8 @@ template class TinyPtrVector { public: typedef llvm::SmallVector VecTy; + typedef typename VecTy::value_type value_type; + llvm::PointerUnion Val; TinyPtrVector() {} @@ -74,9 +76,6 @@ public: typedef EltTy *iterator; iterator begin() { - if (empty()) - return 0; - if (Val.template is()) return Val.getAddrOfPtr1(); @@ -84,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(); } @@ -120,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"); @@ -139,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()) { @@ -160,8 +173,7 @@ public: // benefit to collapsing back to a pointer return Vec->erase(I); } - - return 0; + return end(); } private: