summaryrefslogtreecommitdiffstats
path: root/lib/lz4.c
diff options
context:
space:
mode:
authorYann Collet <Cyan4973@users.noreply.github.com>2018-04-23 22:55:56 (GMT)
committerGitHub <noreply@github.com>2018-04-23 22:55:56 (GMT)
commit0c2ae72ba82e1cabf3b73909dfeb759e57bb7f9e (patch)
tree50f0a217a773790d22f4ba0624289a91d3ee1e01 /lib/lz4.c
parent57cc7daf2241dc36f49ed2f42b418c6567af971c (diff)
parentd1f21883d652ac0abae91bc04924747c82bdbabd (diff)
downloadlz4-0c2ae72ba82e1cabf3b73909dfeb759e57bb7f9e.zip
lz4-0c2ae72ba82e1cabf3b73909dfeb759e57bb7f9e.tar.gz
lz4-0c2ae72ba82e1cabf3b73909dfeb759e57bb7f9e.tar.bz2
Merge pull request #507 from lz4/clangPerf
fixed lz4_fast clang performance
Diffstat (limited to 'lib/lz4.c')
-rw-r--r--lib/lz4.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index 40b2229..f32106c 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -776,9 +776,10 @@ LZ4_FORCE_INLINE int LZ4_compress_generic(
forwardH = LZ4_hashPosition(forwardIp, tableType);
LZ4_putIndexOnHash(current, h, cctx->hashTable, tableType);
- if ((dictIssue == dictSmall) && (matchIndex < prefixIdxLimit)) continue; /* match outside of valid area */
- if ((tableType != byU16) && (current - matchIndex > MAX_DISTANCE)) continue; /* too far - note: works even if matchIndex overflows */
- if (tableType == byU16) assert((current - matchIndex) <= MAX_DISTANCE); /* too_far presumed impossible with byU16 */
+ if ((dictIssue == dictSmall) && (matchIndex < prefixIdxLimit)) continue; /* match outside of valid area */
+ assert(matchIndex < current);
+ if ((tableType != byU16) && (matchIndex+MAX_DISTANCE < current)) continue; /* too far */
+ if (tableType == byU16) assert((current - matchIndex) <= MAX_DISTANCE); /* too_far presumed impossible with byU16 */
if (LZ4_read32(match) == LZ4_read32(ip)) {
if (maybe_extMem) offset = current - matchIndex;
@@ -918,8 +919,9 @@ _next_match:
match = base + matchIndex;
}
LZ4_putIndexOnHash(current, h, cctx->hashTable, tableType);
+ assert(matchIndex < current);
if ( ((dictIssue==dictSmall) ? (matchIndex >= prefixIdxLimit) : 1)
- && ((tableType==byU16) ? 1 : (current - matchIndex <= MAX_DISTANCE))
+ && ((tableType==byU16) ? 1 : (matchIndex+MAX_DISTANCE >= current))
&& (LZ4_read32(match) == LZ4_read32(ip)) ) {
token=op++;
*token=0;
@@ -1304,7 +1306,11 @@ int LZ4_loadDict (LZ4_stream_t* LZ4_dict, const char* dictionary, int dictSize)
DEBUGLOG(4, "LZ4_loadDict (%i bytes from %p into %p)", dictSize, dictionary, LZ4_dict);
- LZ4_prepareTable(dict, 0, tableType);
+ /* It's necessary to reset the context,
+ * and not just continue it with prepareTable()
+ * to avoid any risk of generating overflowing matchIndex
+ * when compressing using this dictionary */
+ LZ4_resetStream(LZ4_dict);
/* We always increment the offset by 64 KB, since, if the dict is longer,
* we truncate it to the last 64k, and if it's shorter, we still want to