Subject: Re: bug#67022: Gzip decompression can be 60% faster using zlib's CRC32

From: "Adler, Mark" <[email-masked]>
Date: Thu, 14 Mar 2024 22:57:23 +0000

On Mar 14, 2024, at 3:46 PM, wrotycz <[email-masked]> wrote:
> 
> 
> Despite that the question is how do I use zlib crc32()? It doesn't give me correct result.
> 
> My 'rig' is this:
> 
> ~~~
> crc = -1
> while (buffer, length = read_data()):
>     {
>     crc = crcfunc(crc, buffer, length)
>     }
> crc = ~crc
> ~~~
> 
> This doesn't work with `crc32_z();’

You would need to read the documentation in zlib.h in order to be able to use its crc32() or crc32_z() correctly. From zlib.h:

   Usage example:

     uLong crc = crc32(0L, Z_NULL, 0);

     while (read_buffer(buffer, length) != EOF) {
       crc = crc32(crc, buffer, length);
     }
     if (crc != original_crc) error();

The initial value returned by crc32(0L, Z_NULL, 0) is 0, not -1. And there is no post inversion. To get your test code to work, it would need to be:

> crc = 0
> while (buffer, length = read_data()):
>     {
>     crc = crc32_z(crc, buffer, length)
>     }