From 28b824921d94c8263cb51dfdee0a149490009f8f Mon Sep 17 00:00:00 2001 From: Dave Watson Date: Fri, 25 Jan 2019 16:01:09 -0800 Subject: decompress_generic: re-add fastpath This is the remaineder of the original 'shortcut'. If true, we can avoid the loop in LZ4_wildCopy, and directly copy instead. --- lib/lz4.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/lz4.c b/lib/lz4.c index 915ee74..a18401a 100644 --- a/lib/lz4.c +++ b/lib/lz4.c @@ -1592,11 +1592,26 @@ LZ4_decompress_generic( length += read_variable_length(&ip, iend - LASTLITERALS + 1, endOnInput, 0, &error); if (error != ok) goto _output_error; if ((safeDecode) && unlikely((uptrval)(op)+length<(uptrval)op)) goto _output_error; /* overflow detection */ - } - length += MINMATCH; + length += MINMATCH; + if (op + length >= oend - FASTLOOP_SAFE_DISTANCE) { + goto safe_match_copy; + } + } else { + length += MINMATCH; + if (op + length >= oend - FASTLOOP_SAFE_DISTANCE) { + goto safe_match_copy; + } - if (op + length >= oend - FASTLOOP_SAFE_DISTANCE) { - goto safe_match_copy; + /* Fastpath check: Avoids a branch in LZ4_wildCopy16 if true */ + if (!(dict == usingExtDict) || (match >= lowPrefix)) { + if (offset >= 8) { + memcpy(op, match, 8); + memcpy(op+8, match+8, 8); + memcpy(op+16, match+16, 2); + op += length; + continue; + } + } } /* match starting within external dictionary */ -- cgit v0.12