From: Yann Collet Date: Tue, 7 Nov 2017 18:53:29 +0000 (-0800) Subject: fixed LZ4HC_countPattern() X-Git-Tag: upstream/1.9.3~11^2~25^2~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a004c1fbee4e5a8793f9dfc1deeafea1d59be486;p=platform%2Fupstream%2Flz4.git 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 --- 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); }