fixed clang performance in lz4_fast
authorYann Collet <cyan@fb.com>
Sat, 21 Apr 2018 01:09:51 +0000 (18:09 -0700)
committerYann Collet <cyan@fb.com>
Sat, 21 Apr 2018 01:09:51 +0000 (18:09 -0700)
commita8a5dfd426cec6e3ac6c689a314aff5817de9ce3
tree8d25ab3efc4d8564e5cc94264c79f6b38da87f0f
parent62d7cdcc741480842a0c217df7cb26ad3946ab32
fixed clang performance in lz4_fast

The simple change from
`matchIndex+MAX_DISTANCE < current`
towards
`current - matchIndex > MAX_DISTANCE`

is enough to generate a 10% performance drop under clang.
Quite massive.
(I missed as my eyes were concentrated on gcc performance at that time).

The second version is more robust, because it also survives a situation where
`matchIndex > current`
due to overflows.

The first version requires matchIndex to not overflow.
Hence were added `assert()` conditions.

The only case where this can happen is with dictCtx compression,
in the case where the dictionary context is not initialized before loading the dictionary.
So it's enough to always initialize the context while loading the dictionary.
lib/lz4.c