]> diplodocus.org Git - nmh/commitdiff
bvector_copy: Use bvector's tiny storage if big enough.
authorRalph Corderoy <ralph@inputplus.co.uk>
Fri, 28 Apr 2017 21:42:46 +0000 (22:42 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Fri, 28 Apr 2017 21:42:46 +0000 (22:42 +0100)
Otherwise a source bvector that's using tiny storage has its bits
duplicated into a malloc'd area when the destination's tiny storage was
sufficient.

sbr/vector.c

index 7df3618..6afe62a 100644 (file)
@@ -79,7 +79,10 @@ bvector_copy (bvector_t dest, bvector_t src) {
 
     if (dest->bits != dest->tiny)
         free(dest->bits);
-    dest->bits = mh_xmalloc (bytes);
+    if (bytes <= sizeof dest->tiny)
+        dest->bits = dest->tiny;
+    else
+        dest->bits = mh_xmalloc (bytes);
     memcpy (dest->bits, src->bits, bytes);
     dest->maxsize = src->maxsize;
 }