diff --git a/meson.build b/meson.build index f6abd9165b8..bde6ec6d5ba 100644 --- a/meson.build +++ b/meson.build @@ -1541,7 +1541,8 @@ else dep_clock = cc.find_library('rt') endif -dep_zlib = dependency('zlib', version : '>= 1.2.9', +# IMPORTANT: We can't upgrade Zlib beyond 1.2.5 because it would break Viewperf. +dep_zlib = dependency('zlib', version : '>= 1.2.3', allow_fallback: true, required : get_option('zlib')) if dep_zlib.found() diff --git a/src/util/crc32.c b/src/util/crc32.c index 59059e4f885..ec5ad2cc94c 100644 --- a/src/util/crc32.c +++ b/src/util/crc32.c @@ -33,15 +33,10 @@ */ -#include "crc32.h" #ifdef HAVE_ZLIB #include -uint32_t -util_hash_crc32(const void *data, size_t size) -{ - return ~crc32_z(0, data, size); -} -#else +#endif +#include "crc32.h" static const uint32_t @@ -122,9 +117,18 @@ util_hash_crc32(const void *data, size_t size) const uint8_t *p = data; uint32_t crc = 0xffffffff; +#ifdef HAVE_ZLIB + /* Prefer zlib's implementation for better performance. + * zlib's uInt is always "unsigned int" while size_t can be 64bit. + * Since 1.2.9 there's crc32_z that takes size_t, but use the more + * available function to avoid build system complications. + */ + if ((uInt)size == size) + return ~crc32(0, data, size); +#endif + while (size--) crc = util_crc32_table[(crc ^ *p++) & 0xff] ^ (crc >> 8); return crc; } -#endif