Merge pull request #139 from pah/fixes/stack-growth-factor
Stack: adjust growth factor
This commit is contained in:
commit
a5ffc5be1c
@ -98,7 +98,13 @@ private:
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void Expand(size_t count) {
|
void Expand(size_t count) {
|
||||||
// Only expand the capacity if the current stack exists. Otherwise just create a stack with initial capacity.
|
// Only expand the capacity if the current stack exists. Otherwise just create a stack with initial capacity.
|
||||||
size_t newCapacity = (stack_ == 0) ? initialCapacity_ : GetCapacity() * 2;
|
size_t newCapacity;
|
||||||
|
if (stack_ == 0)
|
||||||
|
newCapacity = initialCapacity_;
|
||||||
|
else {
|
||||||
|
newCapacity = GetCapacity();
|
||||||
|
newCapacity += (newCapacity + 1) / 2;
|
||||||
|
}
|
||||||
size_t newSize = GetSize() + sizeof(T) * count;
|
size_t newSize = GetSize() + sizeof(T) * count;
|
||||||
if (newCapacity < newSize)
|
if (newCapacity < newSize)
|
||||||
newCapacity = newSize;
|
newCapacity = newSize;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user