Added vector_shrink_to_fit to llstl.h
This commit is contained in:
@@ -287,6 +287,19 @@ inline T* vector_append(std::vector<T>& invec, S32 N)
|
||||
return &(invec[sz]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void vector_shrink_to_fit(std::vector<T>& invec)
|
||||
{
|
||||
//For Windows: We always assume vs2010 or later, which support this c++11 feature with no configuration needed.
|
||||
//For GCC: __cplusplus >= 201103L indicates C++11 support. __GXX_EXPERIMENTAL_CXX0X being set indicates experimental c++0x support. C++11 support replaces C++0x support.
|
||||
// std::vector::shrink_to_fit was added to GCCs C++0x implementation in version 4.5.0.
|
||||
#if defined(LL_WINDOWS) || __cplusplus >= 201103L || (defined(__GXX_EXPERIMENTAL_CXX0X) && __GNUC_MINOR__ >= 5)
|
||||
invec.shrink_to_fit();
|
||||
#else
|
||||
invec(invec.begin(), invec.end()).swap(invec);
|
||||
#endif
|
||||
}
|
||||
|
||||
// call function f to n members starting at first. similar to std::for_each
|
||||
template <class InputIter, class Size, class Function>
|
||||
Function ll_for_n(InputIter first, Size n, Function f)
|
||||
|
||||
@@ -696,14 +696,7 @@ public:
|
||||
(mData.size() > gOctreeReserveCapacity && mData.capacity() > gOctreeReserveCapacity + mData.size() - 1 - (mData.size() - gOctreeReserveCapacity - 1) % 4))
|
||||
{
|
||||
//Shrink to lowest possible (reserve)+4*i size.. Say reserve is 5, here are [size,capacity] pairs. [10,13],[9,9],[8,9],[7,9],[6,9],[5,5],[4,5],[3,5],[2,5],[1,5],[0,5]
|
||||
//For Windows: We always assume vs2010 or later, which support this c++11 feature with no configuration needed.
|
||||
//For GCC: __cplusplus >= 201103L indicates C++11 support. __GXX_EXPERIMENTAL_CXX0X being set indicates experimental c++0x support. C++11 support replaces C++0x support.
|
||||
// std::vector::shrink_to_fit was added to GCCs C++0x implementation in version 4.5.0.
|
||||
#if defined(LL_WINDOWS) || __cplusplus >= 201103L || (defined(__GXX_EXPERIMENTAL_CXX0X) && __GNUC_MINOR__ >= 5)
|
||||
mData.shrink_to_fit();
|
||||
#else
|
||||
std::vector<LLPointer<T> >(mData.begin(), mData.end()).swap(mData); //Need to confirm this works on OSX..
|
||||
#endif
|
||||
vector_shrink_to_fit(mData);
|
||||
}
|
||||
#ifdef LL_OCTREE_STATS
|
||||
if(old_cap != mData.capacity())
|
||||
|
||||
Reference in New Issue
Block a user