diff options
author | John McCall <rjmccall@apple.com> | 2010-08-26 02:11:48 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-08-26 02:11:48 +0000 |
commit | 4672f0f61c0cc1a90d575fcbfd7d905396f81cc6 (patch) | |
tree | db3411cc0ed301ab17d78fc14afa34e2c45194bb /include/llvm/ADT | |
parent | f88c23597aa457f983b3ecd0043c6de2520be1ba (diff) | |
download | external_llvm-4672f0f61c0cc1a90d575fcbfd7d905396f81cc6.zip external_llvm-4672f0f61c0cc1a90d575fcbfd7d905396f81cc6.tar.gz external_llvm-4672f0f61c0cc1a90d575fcbfd7d905396f81cc6.tar.bz2 |
SmallVector's growth policies don't like starting from zero capacity.
I think there are good reasons to change this, but in the interests
of short-term stability, make SmallVector<...,0> reserve non-zero
capacity in its constructors. This means that SmallVector<...,0>
uses more memory than SmallVector<...,1> and should really only be
used (unless/until this workaround is removed) by clients that
care about using SmallVector with an incomplete type.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112147 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT')
-rw-r--r-- | include/llvm/ADT/SmallVector.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h index 3be1787..a76e9c7 100644 --- a/include/llvm/ADT/SmallVector.h +++ b/include/llvm/ADT/SmallVector.h @@ -712,25 +712,33 @@ public: /// members are required. template <typename T> class SmallVector<T,0> : public SmallVectorImpl<T> { + // SmallVector doesn't like growing from zero capacity. As a + // temporary workaround, avoid changing the growth algorithm by + // forcing capacity to be at least 1 in the constructors. + public: SmallVector() : SmallVectorImpl<T>(0) { + this->reserve(1); // workaround } explicit SmallVector(unsigned Size, const T &Value = T()) : SmallVectorImpl<T>(0) { - this->reserve(Size); + this->reserve(Size ? Size : 1); // workaround while (Size--) this->push_back(Value); } template<typename ItTy> SmallVector(ItTy S, ItTy E) : SmallVectorImpl<T>(0) { + if (S == E) this->reserve(1); // workaround this->append(S, E); } SmallVector(const SmallVector &RHS) : SmallVectorImpl<T>(0) { if (!RHS.empty()) SmallVectorImpl<T>::operator=(RHS); + else + this->reserve(1); // workaround } const SmallVector &operator=(const SmallVector &RHS) { |