summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2017-11-07 19:05:48 (GMT)
committerYann Collet <cyan@fb.com>2017-11-07 19:05:48 (GMT)
commit7130bfe5733347d8c84b8f6b8fb34c1397d4a173 (patch)
tree0e9e9b4d37ca93cbc3b85512e07a5066ce156574 /lib
parenta004c1fbee4e5a8793f9dfc1deeafea1d59be486 (diff)
downloadlz4-7130bfe5733347d8c84b8f6b8fb34c1397d4a173.zip
lz4-7130bfe5733347d8c84b8f6b8fb34c1397d4a173.tar.gz
lz4-7130bfe5733347d8c84b8f6b8fb34c1397d4a173.tar.bz2
improved LZ4HC_reverseCountPattern() :
works for any repetitive pattern of length 1, 2 or 4 (but not 3!) works for any endianess
Diffstat (limited to 'lib')
-rw-r--r--lib/lz4hc.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/lz4hc.c b/lib/lz4hc.c
index fbcec98..1880d53 100644
--- a/lib/lz4hc.c
+++ b/lib/lz4hc.c
@@ -161,17 +161,21 @@ static unsigned LZ4HC_countPattern(const BYTE* ip, const BYTE* const iEnd, U32 c
return (unsigned)(ip - iStart);
}
+/* LZ4HC_reverseCountPattern() :
+ * pattern must be a sample of repetitive pattern of length 1, 2 or 4 (but not 3!)
+ * read using natural platform endianess */
static unsigned LZ4HC_reverseCountPattern(const BYTE* ip, const BYTE* const iLow, U32 pattern)
{
const BYTE* const iStart = ip;
- while (likely(ip>=iLow+4)) {
+ while (likely(ip >= iLow+4)) {
if (LZ4_read32(ip-4) != pattern) break;
ip -= 4;
}
while (likely(ip>iLow)) {
- if (ip[-1] != (BYTE)pattern) break;
- ip--;
+ const BYTE* bytePtr = (const BYTE*)(&pattern) + 3; /* works for any endianess */
+ if (ip[-1] != *bytePtr) break;
+ ip--; bytePtr--;
}
return (unsigned)(iStart - ip);