]> granicus.if.org Git - taglib/commitdiff
Reduce redundant memset when resizing ByteVector.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Fri, 15 May 2015 18:46:34 +0000 (03:46 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Fri, 15 May 2015 18:46:34 +0000 (03:46 +0900)
taglib/toolkit/tbytevector.cpp

index 7aeaea9211f87c246d09c91a2946eaf71e9a6e24..ad5d4523539d14ab57023cbebc41c42358c2b763 100644 (file)
@@ -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;
   }