]> granicus.if.org Git - taglib/commitdiff
Revert the last two commits.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Sat, 16 May 2015 02:16:00 +0000 (11:16 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Sat, 16 May 2015 02:16:00 +0000 (11:16 +0900)
But leave the tests unchanged, and add some comments.

taglib/toolkit/tbytevector.cpp

index ad5d4523539d14ab57023cbebc41c42358c2b763..45ad031784d264f6d2d9ac8f0964d6cb750de165 100644 (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;
   }