From 38c3945de300851757d0dd76182ee28aaf8253a4 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Tue, 30 Jul 2019 23:40:58 -0700 Subject: [PATCH] [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. --- lib/lz4hc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lz4hc.c b/lib/lz4hc.c index 596888a..0608ec6 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -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; -- 2.7.4