From: Tsuda Kageyu Date: Fri, 15 May 2015 18:46:34 +0000 (+0900) Subject: Reduce redundant memset when resizing ByteVector. X-Git-Tag: v1.10beta~114^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1f99c93a61085bbd625621cfe0c075bbc323b076;p=taglib Reduce redundant memset when resizing ByteVector. --- diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index 7aeaea92..ad5d4523 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -703,11 +703,15 @@ ByteVector &ByteVector::resize(uint size, char padding) if(size != d->length) { detach(); - if(size > d->data->data.size() - d->offset) - d->data->data.resize(d->offset + size); + const size_t bufferSize = d->data->data.size(); - if(size > d->length) - ::memset(DATA(d) + d->offset + d->length, padding, size - d->length); + 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->length = size; }