From: Nathan Moinvaziri Date: Mon, 15 Nov 2021 04:58:01 +0000 (-0800) Subject: Reuse adler32_len_64 in adler32_c. X-Git-Tag: 2.1.0-beta1~488 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=330445c51b95cc6c8f1dae28876e9992cbc58912;p=thirdparty%2Fzlib-ng.git Reuse adler32_len_64 in adler32_c. --- diff --git a/adler32.c b/adler32.c index 7b245fc84..499adbb60 100644 --- a/adler32.c +++ b/adler32.c @@ -51,30 +51,7 @@ Z_INTERNAL uint32_t adler32_c(uint32_t adler, const unsigned char *buf, size_t l } /* do remaining bytes (less than NMAX, still just one modulo) */ - if (len) { /* avoid modulos if none remaining */ -#ifdef UNROLL_MORE - while (len >= 16) { - len -= 16; - DO16(adler, sum2, buf); - buf += 16; -#else - while (len >= 8) { - len -= 8; - DO8(adler, sum2, buf, 0); - buf += 8; -#endif - } - while (len) { - --len; - adler += *buf++; - sum2 += adler; - } - adler %= BASE; - sum2 %= BASE; - } - - /* return recombined sums */ - return adler | (sum2 << 16); + return adler32_len_64(adler, buf, len, sum2); } #ifdef ZLIB_COMPAT diff --git a/adler32_p.h b/adler32_p.h index adcc79f01..1adc1ccb0 100644 --- a/adler32_p.h +++ b/adler32_p.h @@ -34,14 +34,22 @@ static inline uint32_t adler32_len_16(uint32_t adler, const unsigned char *buf, } adler %= BASE; sum2 %= BASE; /* only added so many BASE's */ + /* return recombined sums */ return adler | (sum2 << 16); } static inline uint32_t adler32_len_64(uint32_t adler, const unsigned char *buf, size_t len, uint32_t sum2) { +#ifdef UNROLL_MORE while (len >= 16) { len -= 16; DO16(adler, sum2, buf); buf += 16; +#else + while (len >= 8) { + len -= 8; + DO8(adler, sum2, buf, 0); + buf += 8; +#endif } /* Process tail (len < 16). */ return adler32_len_16(adler, buf, len, sum2);