X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Futil%2Fcrc32.c;h=425046ab5fd02aa25dd24bedf886edb5076e7b24;hb=46c368907fcf333a19881d28c46e997845d00faf;hp=44d637c0f2015ae15cb787bb019d19009b31b2b2;hpb=86514d84e0beec47c82da4888db12bf07f33cb83;p=mesa.git diff --git a/src/util/crc32.c b/src/util/crc32.c index 44d637c0f20..425046ab5fd 100644 --- a/src/util/crc32.c +++ b/src/util/crc32.c @@ -33,6 +33,9 @@ */ +#ifdef HAVE_ZLIB +#include +#endif #include "crc32.h" @@ -111,9 +114,19 @@ util_crc32_table[256] = { uint32_t util_hash_crc32(const void *data, size_t size) { - uint8_t *p = (uint8_t *)data; + 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);