Skip to content

Commit

Permalink
add some helper methods to make the type more uniform.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157554 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
lattner committed May 28, 2012
1 parent 8620890 commit 2edc74a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions include/llvm/ADT/TinyPtrVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ class TinyPtrVector {
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");

Expand All @@ -139,6 +147,15 @@ class TinyPtrVector {
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>()) {
Expand Down

0 comments on commit 2edc74a

Please sign in to comment.