summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2017-10-25 08:10:53 (GMT)
committerYann Collet <cyan@fb.com>2017-10-25 08:10:53 (GMT)
commita31b7058cb97e4393da55e78a77a1c6f0c9ae038 (patch)
tree5a5e846bf9989a3f8442b103c72ad426acdf2705 /lib
parentdccf8826f1d76efcbdc655e63cc04cdbd1123619 (diff)
downloadlz4-a31b7058cb97e4393da55e78a77a1c6f0c9ae038.zip
lz4-a31b7058cb97e4393da55e78a77a1c6f0c9ae038.tar.gz
lz4-a31b7058cb97e4393da55e78a77a1c6f0c9ae038.tar.bz2
small modification of lz4 decoder to shortcut common case (short branch).
Diffstat (limited to 'lib')
-rw-r--r--lib/lz4.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index 179408d..e0a961f 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -1180,6 +1180,22 @@ LZ4_FORCE_INLINE int LZ4_decompress_generic(
/* get literal length */
unsigned const token = *ip++;
+
+ if (1)
+ if (ip + 14 + 2 <= iend)
+ if ((token < 15*16) & ((token & 0xF) <= 12)) {
+ size_t const ll = token >> ML_BITS;
+ size_t const off = LZ4_readLE16(ip+ll); /* check input validity */
+ if (off >= 16) {
+ size_t const ml = (token & 0xF) + MINMATCH;
+ DEBUGLOG(2, "rest:%u, ll:%2u, ml:%2u, off:%u",
+ (U32)(oend-op), (U32)ll, (U32)ml, (U32)off);
+ memcpy(op, ip, 16); op += ll; ip += ll + 2 /* offset */;
+ memcpy(op, op - off, 16); op += ml;
+ continue;
+ }
+ }
+
if ((length=(token>>ML_BITS)) == RUN_MASK) {
unsigned s;
do {