diff options
author | Yann Collet <Cyan4973@users.noreply.github.com> | 2018-04-23 22:55:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-23 22:55:56 (GMT) |
commit | 0c2ae72ba82e1cabf3b73909dfeb759e57bb7f9e (patch) | |
tree | 50f0a217a773790d22f4ba0624289a91d3ee1e01 /lib/lz4.c | |
parent | 57cc7daf2241dc36f49ed2f42b418c6567af971c (diff) | |
parent | d1f21883d652ac0abae91bc04924747c82bdbabd (diff) | |
download | lz4-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.c | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -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 |