Revert the last two commits.

But leave the tests unchanged, and add some comments.
This commit is contained in:
Tsuda Kageyu 2015-05-16 11:16:00 +09:00
parent 1f99c93a61
commit b021ed44e9

View File

@ -703,15 +703,12 @@ ByteVector &ByteVector::resize(uint size, char padding)
if(size != d->length) {
detach();
const size_t bufferSize = d->data->data.size();
// Remove the excessive length of the internal buffer first to pad correctly.
// This doesn't reallocate the buffer, since std::vector::resize() doesn't
// reallocate the buffer when shrinking.
if(size > bufferSize - d->offset) {
d->data->data.resize(d->offset + size, padding);
::memset(&*end(), padding, bufferSize - (d->length + d->offset));
}
else if(size > d->length) {
::memset(&*end(), padding, size - d->length);
}
d->data->data.resize(d->offset + d->length);
d->data->data.resize(d->offset + size, padding);
d->length = size;
}