[lz4hc] Only allow chain swapping forwards

When the match is very long and found quickly, we can do
matchLength * nbCompares iterations through the chain
swapping, which can really slow down compression.
This commit is contained in:
Nick Terrell 2019-07-30 23:40:58 -07:00
parent be1738aa46
commit 38c3945de3

View File

@ -314,7 +314,7 @@ LZ4HC_InsertAndGetWiderMatch (
if (matchIndex + (U32)longest <= ipIndex) {
U32 distanceToNextMatch = 1;
int pos;
for (pos = 0; pos <= longest - MINMATCH; ++pos) {
for (pos = matchChainPos; pos <= longest - MINMATCH; ++pos) {
U32 const candidateDist = DELTANEXTU16(chainTable, matchIndex + (U32)pos);
if (candidateDist > distanceToNextMatch) {
distanceToNextMatch = candidateDist;