Repository: commons-compress Updated Branches: refs/heads/master b6657ca9a -> 72fec65e1
stop searching once the optimal match has been found Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/cfc68acf Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/cfc68acf Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/cfc68acf Branch: refs/heads/master Commit: cfc68acf12b856e59845e3ad2eace27bc257e8eb Parents: b6657ca Author: Stefan Bodewig <[email protected]> Authored: Wed Feb 8 17:54:50 2017 +0100 Committer: Stefan Bodewig <[email protected]> Committed: Wed Feb 8 17:54:50 2017 +0100 ---------------------------------------------------------------------- .../compress/compressors/lz77support/LZ77Compressor.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/cfc68acf/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java b/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java index 48884cd..0dcdb2a 100644 --- a/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java +++ b/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java @@ -19,6 +19,7 @@ package org.apache.commons.compress.compressors.lz77support; import java.io.IOException; +import java.util.Arrays; /** * Helper class for compression algorithms that use the ideas of LZ77. @@ -242,9 +243,7 @@ public class LZ77Compressor { window = new byte[wSize * 2]; wMask = wSize - 1; head = new int[HASH_SIZE]; - for (int i = 0; i < HASH_SIZE; i++) { - head[i] = NO_MATCH; - } + Arrays.fill(head, NO_MATCH); prev = new int[wSize]; } @@ -486,6 +485,10 @@ public class LZ77Compressor { if (currentLength > longestMatchLength) { longestMatchLength = currentLength; matchStart = matchHead; + if (currentLength == maxPossibleLength) { + // no need to search any further + break; + } } matchHead = prev[matchHead & wMask]; }
