diff options
author | Chris Lattner <sabre@nondot.org> | 2012-05-28 01:29:59 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2012-05-28 01:29:59 +0000 |
commit | 9a49ffdb47e38fba6b5455482a6f7439140da365 (patch) | |
tree | d84bfe07e7f351f0dc05bb1bc7a1d62364416a67 | |
parent | c4c0e8aa9ab4e0a8b4c9dd74a00e0757bccadea0 (diff) | |
download | bcm5719-llvm-9a49ffdb47e38fba6b5455482a6f7439140da365.tar.gz bcm5719-llvm-9a49ffdb47e38fba6b5455482a6f7439140da365.zip |
add some helper methods to make the type more uniform.
llvm-svn: 157554
-rw-r--r-- | llvm/include/llvm/ADT/TinyPtrVector.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/include/llvm/ADT/TinyPtrVector.h b/llvm/include/llvm/ADT/TinyPtrVector.h index f9b7d559c39..8f3925c9c55 100644 --- a/llvm/include/llvm/ADT/TinyPtrVector.h +++ b/llvm/include/llvm/ADT/TinyPtrVector.h @@ -120,6 +120,14 @@ public: return Val.template get<VecTy*>()->front(); } + EltTy back() const { + assert(!empty() && "vector empty"); + if (EltTy V = Val.template dyn_cast<EltTy>()) + return V; + return Val.template get<VecTy*>()->back(); + } + + void push_back(EltTy NewVal) { assert(NewVal != 0 && "Can't add a null value"); @@ -139,6 +147,15 @@ public: Val.template get<VecTy*>()->push_back(NewVal); } + void pop_back() { + // If we have a single value, convert to empty. + if (Val.template is<EltTy>()) + Val = (EltTy)0; + 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>()) { |