From: Michael Schroeder Date: Wed, 18 Nov 2015 14:41:45 +0000 (+0100) Subject: Move rounding to block size into solv_extend_realloc() X-Git-Tag: 0.6.15~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=464e9c2dd2f28b738caeda7b7ea5d14c4d8ec2b5;p=thirdparty%2Flibsolv.git Move rounding to block size into solv_extend_realloc() As this is not not very often and thus does not need to be inlined. --- diff --git a/src/util.c b/src/util.c index 8be29351..d611297e 100644 --- a/src/util.c +++ b/src/util.c @@ -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; diff --git a/src/util.h b/src/util.h index 60dd49cc..5f7a93ab 100644 --- a/src/util.h +++ b/src/util.h @@ -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; }