Expand the internal buffer of ByteVector only if really needed.

Add tests for all execution paths of ByteVector::resize().
This commit is contained in:
Tsuda Kageyu
2015-05-14 11:20:35 +09:00
parent ff8443f33a
commit a924ca0db7
2 changed files with 52 additions and 8 deletions

View File

@ -702,8 +702,13 @@ ByteVector &ByteVector::resize(uint size, char padding)
{
if(size != d->length) {
detach();
d->data->data.resize(d->offset + d->length);
d->data->data.resize(d->offset + size, padding);
if(size > d->data->data.size() - d->offset)
d->data->data.resize(d->offset + size);
if(size > d->length)
::memset(DATA(d) + d->offset + d->length, padding, size - d->length);
d->length = size;
}