]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Move rounding to block size into solv_extend_realloc()
authorMichael Schroeder <mls@suse.de>
Wed, 18 Nov 2015 14:41:45 +0000 (15:41 +0100)
committerMichael Schroeder <mls@suse.de>
Wed, 18 Nov 2015 14:41:45 +0000 (15:41 +0100)
As this is not not very often and thus does not need to be
inlined.

src/util.c
src/util.h

index 8be293519c66d056344e5d4e0434aa5882da0bb8..d611297e20c8d9e3f3a502c1d31e8a40670ab659 100644 (file)
@@ -82,6 +82,7 @@ void *
 solv_extend_realloc(void *old, size_t len, size_t size, size_t block)
 {
   size_t xblock = (block + 1) << 5;
+  len = (len + block) & ~block;
   if (len >= xblock && xblock)
     {
       xblock <<= 1;
index 60dd49cc74b80e7bda3095b4dbe3ee20d6895f09..5f7a93ab1e17adf473f520a95c0a76fa47593036 100644 (file)
@@ -49,12 +49,12 @@ static inline void *solv_extend(void *buf, size_t len, size_t nmemb, size_t size
   if (nmemb == 1)
     {
       if ((len & block) == 0)
-       buf = solv_extend_realloc(buf, len + (1 + block), size, block);
+       buf = solv_extend_realloc(buf, len + 1, size, block);
     }
   else
     {
       if (((len - 1) | block) != ((len + nmemb - 1) | block))
-       buf = solv_extend_realloc(buf, (len + (nmemb + block)) & ~block, size, block);
+       buf = solv_extend_realloc(buf, len + nmemb, size, block);
     }
   return buf;
 }
@@ -77,7 +77,7 @@ static inline void *solv_zextend(void *buf, size_t len, size_t nmemb, size_t siz
 static inline void *solv_extend_resize(void *buf, size_t len, size_t size, size_t block)
 {
   if (len)
-    buf = solv_extend_realloc(buf, (len + block) & ~block, size, block);
+    buf = solv_extend_realloc(buf, len, size, block);
   return buf;
 }
 
@@ -86,7 +86,7 @@ static inline void *solv_calloc_block(size_t len, size_t size, size_t block)
   void *buf;
   if (!len)
     return 0;
-  buf = solv_extend_realloc((void *)0, (len + block) & ~block, size, block);
+  buf = solv_extend_realloc((void *)0, len, size, block);
   memset(buf, 0, ((len + block) & ~block) * size);
   return buf;
 }