mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-20 05:38:50 +00:00
add resize, move swap out of line
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29823 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d520dd7a24
commit
57b79795b3
@ -112,43 +112,20 @@ public:
|
|||||||
End = Begin;
|
End = Begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(SmallVectorImpl &RHS) {
|
void resize(unsigned N) {
|
||||||
if (this == &RHS) return;
|
if (N < size()) {
|
||||||
|
destroy_range(Begin+N, End);
|
||||||
// We can only avoid copying elements if neither vector is small.
|
End = Begin+N;
|
||||||
if (!isSmall() && !RHS.isSmall()) {
|
} else if (N > size()) {
|
||||||
std::swap(Begin, RHS.Begin);
|
if (Begin+N > Capacity)
|
||||||
std::swap(End, RHS.End);
|
grow(N);
|
||||||
std::swap(Capacity, RHS.Capacity);
|
construct_range(End, Begin+N, T());
|
||||||
return;
|
End = Begin+N;
|
||||||
}
|
|
||||||
if (Begin+RHS.size() > Capacity)
|
|
||||||
grow(RHS.size());
|
|
||||||
if (RHS.begin()+size() > RHS.Capacity)
|
|
||||||
RHS.grow(size());
|
|
||||||
|
|
||||||
// Swap the shared elements.
|
|
||||||
unsigned NumShared = size();
|
|
||||||
if (NumShared > RHS.size()) NumShared = RHS.size();
|
|
||||||
for (unsigned i = 0; i != NumShared; ++i)
|
|
||||||
std::swap(Begin[i], RHS[i]);
|
|
||||||
|
|
||||||
// Copy over the extra elts.
|
|
||||||
if (size() > RHS.size()) {
|
|
||||||
unsigned EltDiff = size() - RHS.size();
|
|
||||||
std::uninitialized_copy(Begin+NumShared, End, RHS.End);
|
|
||||||
RHS.End += EltDiff;
|
|
||||||
destroy_range(Begin+NumShared, End);
|
|
||||||
End = Begin+NumShared;
|
|
||||||
} else if (RHS.size() > size()) {
|
|
||||||
unsigned EltDiff = RHS.size() - size();
|
|
||||||
std::uninitialized_copy(RHS.Begin+NumShared, RHS.End, End);
|
|
||||||
End += EltDiff;
|
|
||||||
destroy_range(RHS.Begin+NumShared, RHS.End);
|
|
||||||
RHS.End = RHS.Begin+NumShared;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void swap(SmallVectorImpl &RHS);
|
||||||
|
|
||||||
/// append - Add the specified range to the end of the SmallVector.
|
/// append - Add the specified range to the end of the SmallVector.
|
||||||
///
|
///
|
||||||
template<typename in_iter>
|
template<typename in_iter>
|
||||||
@ -168,8 +145,7 @@ public:
|
|||||||
if (Begin+NumElts > Capacity)
|
if (Begin+NumElts > Capacity)
|
||||||
grow(NumElts);
|
grow(NumElts);
|
||||||
End = Begin+NumElts;
|
End = Begin+NumElts;
|
||||||
for (; NumElts; --NumElts)
|
construct_range(Begin, End, Elt);
|
||||||
new (Begin+NumElts-1) T(Elt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void erase(iterator I) {
|
void erase(iterator I) {
|
||||||
@ -221,6 +197,12 @@ private:
|
|||||||
/// least one more element or MinSize if specified.
|
/// least one more element or MinSize if specified.
|
||||||
void grow(unsigned MinSize = 0);
|
void grow(unsigned MinSize = 0);
|
||||||
|
|
||||||
|
void construct_range(T *S, T *E, const T &Elt) {
|
||||||
|
for (; S != E; ++S)
|
||||||
|
new (S) T(Elt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void destroy_range(T *S, T *E) {
|
void destroy_range(T *S, T *E) {
|
||||||
while (S != E) {
|
while (S != E) {
|
||||||
E->~T();
|
E->~T();
|
||||||
@ -254,6 +236,44 @@ void SmallVectorImpl<T>::grow(unsigned MinSize) {
|
|||||||
Capacity = Begin+NewCapacity;
|
Capacity = Begin+NewCapacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void SmallVectorImpl<T>::swap(SmallVectorImpl<T> &RHS) {
|
||||||
|
if (this == &RHS) return;
|
||||||
|
|
||||||
|
// We can only avoid copying elements if neither vector is small.
|
||||||
|
if (!isSmall() && !RHS.isSmall()) {
|
||||||
|
std::swap(Begin, RHS.Begin);
|
||||||
|
std::swap(End, RHS.End);
|
||||||
|
std::swap(Capacity, RHS.Capacity);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Begin+RHS.size() > Capacity)
|
||||||
|
grow(RHS.size());
|
||||||
|
if (RHS.begin()+size() > RHS.Capacity)
|
||||||
|
RHS.grow(size());
|
||||||
|
|
||||||
|
// Swap the shared elements.
|
||||||
|
unsigned NumShared = size();
|
||||||
|
if (NumShared > RHS.size()) NumShared = RHS.size();
|
||||||
|
for (unsigned i = 0; i != NumShared; ++i)
|
||||||
|
std::swap(Begin[i], RHS[i]);
|
||||||
|
|
||||||
|
// Copy over the extra elts.
|
||||||
|
if (size() > RHS.size()) {
|
||||||
|
unsigned EltDiff = size() - RHS.size();
|
||||||
|
std::uninitialized_copy(Begin+NumShared, End, RHS.End);
|
||||||
|
RHS.End += EltDiff;
|
||||||
|
destroy_range(Begin+NumShared, End);
|
||||||
|
End = Begin+NumShared;
|
||||||
|
} else if (RHS.size() > size()) {
|
||||||
|
unsigned EltDiff = RHS.size() - size();
|
||||||
|
std::uninitialized_copy(RHS.Begin+NumShared, RHS.End, End);
|
||||||
|
End += EltDiff;
|
||||||
|
destroy_range(RHS.Begin+NumShared, RHS.End);
|
||||||
|
RHS.End = RHS.Begin+NumShared;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const SmallVectorImpl<T> &
|
const SmallVectorImpl<T> &
|
||||||
SmallVectorImpl<T>::operator=(const SmallVectorImpl<T> &RHS) {
|
SmallVectorImpl<T>::operator=(const SmallVectorImpl<T> &RHS) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user