Merge "Avoid unnecessary allocation in VectorImpl" into main
This commit is contained in:
commit
5684f3e059
1 changed files with 2 additions and 1 deletions
|
|
@ -463,7 +463,8 @@ void VectorImpl::_shrink(size_t where, size_t amount)
|
|||
size_t new_size;
|
||||
LOG_ALWAYS_FATAL_IF(__builtin_sub_overflow(mCount, amount, &new_size));
|
||||
|
||||
if (new_size < (capacity() / 2)) {
|
||||
const size_t prev_capacity = capacity();
|
||||
if (new_size < (prev_capacity / 2) && prev_capacity > kMinVectorCapacity) {
|
||||
// NOTE: (new_size * 2) is safe because capacity didn't overflow and
|
||||
// new_size < (capacity / 2)).
|
||||
const size_t new_capacity = max(kMinVectorCapacity, new_size * 2);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue