diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2012-07-31 02:48:31 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2012-07-31 02:48:31 +0000 |
commit | 40dab1059e72d3af59f2523fa8a7d05f40dafca5 (patch) | |
tree | 519ea5f226ef55e44f564d4a7f798dbdba9a9bc4 /include/llvm/ADT/TinyPtrVector.h | |
parent | 34af6f597b09c13fba7d3a1960c0810cfc30beff (diff) | |
download | external_llvm-40dab1059e72d3af59f2523fa8a7d05f40dafca5.zip external_llvm-40dab1059e72d3af59f2523fa8a7d05f40dafca5.tar.gz external_llvm-40dab1059e72d3af59f2523fa8a7d05f40dafca5.tar.bz2 |
Bring TinyPtrVector under test. Somehow we never picked up unit tests
for this class. These tests exercise most of the basic properties, but
the API for TinyPtrVector is very strange currently. My plan is to start
fleshing out the API to match that of SmallVector, but I wanted a test
for what is there first.
Sadly, it doesn't look reasonable to just re-use the SmallVector tests,
as this container can only ever store pointers, and much of the
SmallVector testing is to get construction and destruction right.
Just to get this basic test working, I had to add value_type to the
interface.
While here I found a subtle bug in the combination of 'erase', 'begin',
and 'end'. Both 'begin' and 'end' wanted to use a null pointer to
indicate the "end" iterator of an empty vector, regardless of whether
there is actually a vector allocated or the pointer union is null.
Everything else was fine with this except for erase. If you erase the
last element of a vector after it has held more than one element, we
return the end iterator of the underlying SmallVector which need not be
a null pointer. Instead, simply use the pointer, and poniter + size()
begin/end definitions in the tiny case, and delegate to the inner vector
whenever it is present.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161024 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/TinyPtrVector.h')
-rw-r--r-- | include/llvm/ADT/TinyPtrVector.h | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/include/llvm/ADT/TinyPtrVector.h b/include/llvm/ADT/TinyPtrVector.h index 8f3925c..ca624c6 100644 --- a/include/llvm/ADT/TinyPtrVector.h +++ b/include/llvm/ADT/TinyPtrVector.h @@ -27,6 +27,8 @@ template <typename EltTy> class TinyPtrVector { public: typedef llvm::SmallVector<EltTy, 4> VecTy; + typedef typename VecTy::value_type value_type; + llvm::PointerUnion<EltTy, VecTy*> Val; TinyPtrVector() {} @@ -74,9 +76,6 @@ public: typedef EltTy *iterator; iterator begin() { - if (empty()) - return 0; - if (Val.template is<EltTy>()) return Val.getAddrOfPtr1(); @@ -84,11 +83,8 @@ public: } iterator end() { - if (empty()) - return 0; - if (Val.template is<EltTy>()) - return begin() + 1; + return begin() + (Val.isNull() ? 0 : 1); return Val.template get<VecTy *>()->end(); } @@ -177,8 +173,7 @@ public: // benefit to collapsing back to a pointer return Vec->erase(I); } - - return 0; + return end(); } private: |