[llvm-commits] [llvm] r112147 - /llvm/trunk/include/llvm/ADT/SmallVector.h
John McCall
rjmccall at apple.com
Wed Aug 25 19:11:48 PDT 2010
Author: rjmccall
Date: Wed Aug 25 21:11:48 2010
New Revision: 112147
URL: http://llvm.org/viewvc/llvm-project?rev=112147&view=rev
Log:
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.
Modified:
llvm/trunk/include/llvm/ADT/SmallVector.h
Modified: llvm/trunk/include/llvm/ADT/SmallVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?rev=112147&r1=112146&r2=112147&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SmallVector.h (original)
+++ llvm/trunk/include/llvm/ADT/SmallVector.h Wed Aug 25 21:11:48 2010
@@ -712,25 +712,33 @@
/// 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) {
More information about the llvm-commits
mailing list