diff options
author | Chris Lattner <sabre@nondot.org> | 2006-08-16 01:23:31 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-08-16 01:23:31 +0000 |
commit | 2e6baf626d2096eade89e5305bc09e369a761516 (patch) | |
tree | 725e4ca56133142392dc6a88481ab25ca41be328 /include/llvm/ADT | |
parent | 103febea8e0d60ce2e3c942444b81abe5d5294db (diff) | |
download | external_llvm-2e6baf626d2096eade89e5305bc09e369a761516.zip external_llvm-2e6baf626d2096eade89e5305bc09e369a761516.tar.gz external_llvm-2e6baf626d2096eade89e5305bc09e369a761516.tar.bz2 |
Bugfixes for smallvector when the element size is small and N is small.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29720 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT')
-rw-r--r-- | include/llvm/ADT/SmallVector.h | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h index ae25884..66e268c 100644 --- a/include/llvm/ADT/SmallVector.h +++ b/include/llvm/ADT/SmallVector.h @@ -228,17 +228,30 @@ class SmallVector : public SmallVectorImpl<T> { /// InlineElts - These are 'N-1' elements that are stored inline in the body /// of the vector. The extra '1' element is stored in SmallVectorImpl. typedef typename SmallVectorImpl<T>::U U; - U InlineElts[(sizeof(T)*N+sizeof(U)-1)/sizeof(U) - 1]; + enum { + // MinUs - The number of U's require to cover N T's. + MinUs = (sizeof(T)*N+sizeof(U)-1)/sizeof(U), + + // NumInlineEltsElts - The number of elements actually in this array. There + // is already one in the parent class, and we have to round up to avoid + // having a zero-element array. + NumInlineEltsElts = (MinUs - 1) > 0 ? (MinUs - 1) : 1, + + // NumTsAvailable - The number of T's we actually have space for, which may + // be more than N due to rounding. + NumTsAvailable = (NumInlineEltsElts+1)*sizeof(U) / sizeof(T) + }; + U InlineElts[NumInlineEltsElts]; public: - SmallVector() : SmallVectorImpl<T>(N) { + SmallVector() : SmallVectorImpl<T>(NumTsAvailable) { } template<typename ItTy> - SmallVector(ItTy S, ItTy E) : SmallVectorImpl<T>(N) { + SmallVector(ItTy S, ItTy E) : SmallVectorImpl<T>(NumTsAvailable) { append(S, E); } - SmallVector(const SmallVector &RHS) : SmallVectorImpl<T>(N) { + SmallVector(const SmallVector &RHS) : SmallVectorImpl<T>(NumTsAvailable) { operator=(RHS); } }; |