# optimize flate decompression · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/bb304796f466b4fd15a4adac7ffbb81ace95d2a4)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: bb304796f466b4fd15a4adac7ffbb81ace95d2a4

Requested commit: bb304796f466b4fd15a4adac7ffbb81ace95d2a4

Commit: bb304796f466b4fd15a4adac7ffbb81ace95d2a4

Tree: e4825a8af25fcb0063b5a29675e15adf41c2db0d

Author: Kendall Condon

Committer: Andrew Kelley

## Message

```
optimize flate decompression

Matches now use memcpy and memset when possible.

Block loops have been rewritten to be more optimizer friendly.

Reworks Symbol and HuffmanDecoder
* Symbol now only includes the value and number of code bits.
  decodeSymbol returns only the value.
* HuffmanDecoder now takes the regular bits instead of the reversed.
* Code table construction now uses buckets instead of sorting.
* For linked codes, the value field of Symbol is now used as the next
  index. The actual value is the element index.
* InvalidCode is now detected only once with a special linked index.

Performance is 39.7% faster than before and 1.1% faster than gzip using
a sample created from compressing a tar of the src directory.

```

## Parents

- [333055ced72ae73c1ec74a66aa9436291d8b7d1d](https://git.cafe/gitcafe/zig/commit/333055ced72ae73c1ec74a66aa9436291d8b7d1d?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/bb304796f466b4fd15a4adac7ffbb81ace95d2a4?format=markdown)
