From a004c1fbee4e5a8793f9dfc1deeafea1d59be486 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 7 Nov 2017 10:53:29 -0800 Subject: fixed LZ4HC_countPattern() - works with byte values other than `0` - works for any repetitive pattern of length 1, 2 or 4 (but not 3!) - works for little and big endian systems - preserve speed of previous implementation --- lib/lz4hc.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/lz4hc.c b/lib/lz4hc.c index 0cda77c..fbcec98 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -130,20 +130,34 @@ static int LZ4HC_countBack(const BYTE* const ip, const BYTE* const match, return back; } -static unsigned LZ4HC_countPattern(const BYTE* ip, const BYTE* const iEnd, reg_t pattern) +/* LZ4HC_countPattern() : + * pattern32 must be a sample of repetitive pattern of length 1, 2 or 4 (but not 3!) */ +static unsigned LZ4HC_countPattern(const BYTE* ip, const BYTE* const iEnd, U32 const pattern32) { const BYTE* const iStart = ip; + reg_t const pattern = (sizeof(pattern)==8) ? (reg_t)pattern32 + (((reg_t)pattern32) << 32) : pattern32; - while (likely(ip>= 8; + } + } else { /* big endian */ + U32 bitOffset = (sizeof(pattern)*8) - 8; + while (ip < iEnd) { + BYTE const byte = (BYTE)(pattern >> bitOffset); + if (*ip != byte) break; + ip ++; bitOffset -= 8; + } + } + return (unsigned)(ip - iStart); } -- cgit v0.12