mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-17 18:24:34 +00:00
move code out of line so that GCC doesn't inline it at -O3
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29636 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -131,7 +131,49 @@ public:
|
|||||||
new (Begin+NumElts-1) T(Elt);
|
new (Begin+NumElts-1) T(Elt);
|
||||||
}
|
}
|
||||||
|
|
||||||
const SmallVectorImpl &operator=(const SmallVectorImpl &RHS) {
|
const SmallVectorImpl &operator=(const SmallVectorImpl &RHS);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// isSmall - Return true if this is a smallvector which has not had dynamic
|
||||||
|
/// memory allocated for it.
|
||||||
|
bool isSmall() const {
|
||||||
|
return (void*)Begin == (void*)&FirstEl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// grow - double the size of the allocated memory, guaranteeing space for at
|
||||||
|
/// least one more element or MinSize if specified.
|
||||||
|
void grow(unsigned MinSize = 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Define this out-of-line to dissuade the C++ compiler from inlining it.
|
||||||
|
template <typename T>
|
||||||
|
void SmallVectorImpl<T>::grow(unsigned MinSize) {
|
||||||
|
unsigned CurCapacity = Capacity-Begin;
|
||||||
|
unsigned CurSize = size();
|
||||||
|
unsigned NewCapacity = 2*CurCapacity;
|
||||||
|
if (NewCapacity < MinSize)
|
||||||
|
NewCapacity = MinSize;
|
||||||
|
T *NewElts = reinterpret_cast<T*>(new char[NewCapacity*sizeof(T)]);
|
||||||
|
|
||||||
|
// Copy the elements over.
|
||||||
|
std::uninitialized_copy(Begin, End, NewElts);
|
||||||
|
|
||||||
|
// Destroy the original elements.
|
||||||
|
for (iterator I = Begin, E = End; I != E; ++I)
|
||||||
|
I->~T();
|
||||||
|
|
||||||
|
// If this wasn't grown from the inline copy, deallocate the old space.
|
||||||
|
if (!isSmall())
|
||||||
|
delete[] (char*)Begin;
|
||||||
|
|
||||||
|
Begin = NewElts;
|
||||||
|
End = NewElts+CurSize;
|
||||||
|
Capacity = Begin+NewCapacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
const SmallVectorImpl<T> &
|
||||||
|
SmallVectorImpl<T>::operator=(const SmallVectorImpl<T> &RHS) {
|
||||||
// Avoid self-assignment.
|
// Avoid self-assignment.
|
||||||
if (this == &RHS) return *this;
|
if (this == &RHS) return *this;
|
||||||
|
|
||||||
@@ -171,42 +213,7 @@ public:
|
|||||||
|
|
||||||
// Set end.
|
// Set end.
|
||||||
End = Begin+RHSSize;
|
End = Begin+RHSSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
/// isSmall - Return true if this is a smallvector which has not had dynamic
|
|
||||||
/// memory allocated for it.
|
|
||||||
bool isSmall() const {
|
|
||||||
return (void*)Begin == (void*)&FirstEl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// grow - double the size of the allocated memory, guaranteeing space for at
|
|
||||||
/// least one more element or MinSize if specified.
|
|
||||||
void grow(unsigned MinSize = 0) {
|
|
||||||
unsigned CurCapacity = Capacity-Begin;
|
|
||||||
unsigned CurSize = size();
|
|
||||||
unsigned NewCapacity = 2*CurCapacity;
|
|
||||||
if (NewCapacity < MinSize)
|
|
||||||
NewCapacity = MinSize;
|
|
||||||
T *NewElts = reinterpret_cast<T*>(new char[NewCapacity*sizeof(T)]);
|
|
||||||
|
|
||||||
// Copy the elements over.
|
|
||||||
std::uninitialized_copy(Begin, End, NewElts);
|
|
||||||
|
|
||||||
// Destroy the original elements.
|
|
||||||
for (iterator I = Begin, E = End; I != E; ++I)
|
|
||||||
I->~T();
|
|
||||||
|
|
||||||
// If this wasn't grown from the inline copy, deallocate the old space.
|
|
||||||
if (!isSmall())
|
|
||||||
delete[] (char*)Begin;
|
|
||||||
|
|
||||||
Begin = NewElts;
|
|
||||||
End = NewElts+CurSize;
|
|
||||||
Capacity = Begin+NewCapacity;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/// SmallVector - This is a 'vector' (really, a variable-sized array), optimized
|
/// SmallVector - This is a 'vector' (really, a variable-sized array), optimized
|
||||||
/// for the case when the array is small. It contains some number of elements
|
/// for the case when the array is small. It contains some number of elements
|
||||||
|
Reference in New Issue
Block a user