#include "llvm/Support/AlignOf.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/MathExtras.h"
#include "llvm/Support/type_traits.h"
#include <algorithm>
#include <cassert>
return size_t((char*)CapacityX - (char*)BeginX);
}
- bool empty() const { return BeginX == EndX; }
+ bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const { return BeginX == EndX; }
};
template <typename T, unsigned N> struct SmallVectorStorage;
}
reference front() {
+ assert(!empty());
return begin()[0];
}
const_reference front() const {
+ assert(!empty());
return begin()[0];
}
reference back() {
+ assert(!empty());
return end()[-1];
}
const_reference back() const {
+ assert(!empty());
return end()[-1];
}
};
/// std::move, but not all stdlibs actually provide that.
template<typename It1, typename It2>
static It2 move(It1 I, It1 E, It2 Dest) {
-#if LLVM_USE_RVALUE_REFERENCES
for (; I != E; ++I, ++Dest)
*Dest = ::std::move(*I);
return Dest;
-#else
- return ::std::copy(I, E, Dest);
-#endif
}
/// move_backward - Use move-assignment to move the range
/// std::move_backward, but not all stdlibs actually provide that.
template<typename It1, typename It2>
static It2 move_backward(It1 I, It1 E, It2 Dest) {
-#if LLVM_USE_RVALUE_REFERENCES
while (I != E)
*--Dest = ::std::move(*--E);
return Dest;
-#else
- return ::std::copy_backward(I, E, Dest);
-#endif
}
/// uninitialized_move - Move the range [I, E) into the uninitialized
/// memory starting with "Dest", constructing elements as needed.
template<typename It1, typename It2>
static void uninitialized_move(It1 I, It1 E, It2 Dest) {
-#if LLVM_USE_RVALUE_REFERENCES
for (; I != E; ++I, ++Dest)
::new ((void*) &*Dest) T(::std::move(*I));
-#else
- ::std::uninitialized_copy(I, E, Dest);
-#endif
}
/// uninitialized_copy - Copy the range [I, E) onto the uninitialized
goto Retry;
}
-#if LLVM_USE_RVALUE_REFERENCES
void push_back(T &&Elt) {
if (this->EndX < this->CapacityX) {
Retry:
this->grow();
goto Retry;
}
-#endif
-
+
void pop_back() {
this->setEnd(this->end()-1);
this->end()->~T();
void SmallVectorTemplateBase<T, isPodLike>::grow(size_t MinSize) {
size_t CurCapacity = this->capacity();
size_t CurSize = this->size();
- size_t NewCapacity = 2*CurCapacity + 1; // Always grow, even from zero.
+ // Always grow, even from zero.
+ size_t NewCapacity = size_t(NextPowerOf2(CurCapacity+2));
if (NewCapacity < MinSize)
NewCapacity = MinSize;
T *NewElts = static_cast<T*>(malloc(NewCapacity*sizeof(T)));
this->grow(N);
}
- T pop_back_val() {
-#if LLVM_USE_RVALUE_REFERENCES
+ T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val() {
T Result = ::std::move(this->back());
-#else
- T Result = this->back();
-#endif
this->pop_back();
return Result;
}
void assign(unsigned NumElts, const T &Elt) {
clear();
- if (this->capacity() < NumElts)
- this->grow(NumElts);
- this->setEnd(this->begin()+NumElts);
- std::uninitialized_fill(this->begin(), this->end(), Elt);
+ append(NumElts, Elt);
+ }
+
+ template <typename in_iter> void assign(in_iter S, in_iter E) {
+ clear();
+ append(S, E);
}
iterator erase(iterator I) {
return(N);
}
-#if LLVM_USE_RVALUE_REFERENCES
iterator insert(iterator I, T &&Elt) {
if (I == this->end()) { // Important special case for empty vector.
this->push_back(::std::move(Elt));
I = this->begin()+EltNo;
goto Retry;
}
-#endif
iterator insert(iterator I, const T &Elt) {
if (I == this->end()) { // Important special case for empty vector.
SmallVectorImpl &operator=(const SmallVectorImpl &RHS);
-#if LLVM_USE_RVALUE_REFERENCES
SmallVectorImpl &operator=(SmallVectorImpl &&RHS);
-#endif
bool operator==(const SmallVectorImpl &RHS) const {
if (this->size() != RHS.size()) return false;
return *this;
}
-#if LLVM_USE_RVALUE_REFERENCES
template <typename T>
SmallVectorImpl<T> &SmallVectorImpl<T>::operator=(SmallVectorImpl<T> &&RHS) {
// Avoid self-assignment.
RHS.clear();
return *this;
}
-#endif
/// Storage for the SmallVector elements which aren't contained in
/// SmallVectorTemplateCommon. There are 'N-1' elements here. The remaining '1'
return *this;
}
-#if LLVM_USE_RVALUE_REFERENCES
SmallVector(SmallVector &&RHS) : SmallVectorImpl<T>(N) {
if (!RHS.empty())
SmallVectorImpl<T>::operator=(::std::move(RHS));
SmallVectorImpl<T>::operator=(::std::move(RHS));
return *this;
}
-#endif
-
};
template<typename T, unsigned N>