From 010272b62e2ee9407513643f9eb85920d4a0da63 Mon Sep 17 00:00:00 2001 From: David Heidelberg Date: Fri, 26 Jan 2024 23:38:24 +0100 Subject: [PATCH] util: use crc32_z instead of crc32 and bump zlib dep to 1.2.9 1.2.9 has been released in January 2017, so let's assume we'll find it everywhere. Reviewed-by: Dylan Baker Acked-by: Erik Faye-Lund Signed-off-by: David Heidelberg Part-of: --- meson.build | 2 +- src/util/crc32.c | 20 ++++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/meson.build b/meson.build index 2bfcb678b89..9153910e8a4 100644 --- a/meson.build +++ b/meson.build @@ -1537,7 +1537,7 @@ else dep_clock = cc.find_library('rt') endif -dep_zlib = dependency('zlib', version : '>= 1.2.3', +dep_zlib = dependency('zlib', version : '>= 1.2.9', allow_fallback: true, required : get_option('zlib')) if dep_zlib.found() diff --git a/src/util/crc32.c b/src/util/crc32.c index ec5ad2cc94c..59059e4f885 100644 --- a/src/util/crc32.c +++ b/src/util/crc32.c @@ -33,10 +33,15 @@ */ +#include "crc32.h" #ifdef HAVE_ZLIB #include -#endif -#include "crc32.h" +uint32_t +util_hash_crc32(const void *data, size_t size) +{ + return ~crc32_z(0, data, size); +} +#else static const uint32_t @@ -117,18 +122,9 @@ 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