minor cosmetics

This commit is contained in:
Yann Collet 2016-02-11 04:17:50 +01:00
parent 490aa68b18
commit 4488661678
7 changed files with 87 additions and 157 deletions

View File

@ -1465,7 +1465,7 @@ MEM_STATIC unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr)
/* ************************************************************** /* **************************************************************
* Includes * Dependencies
****************************************************************/ ****************************************************************/
#include <stdlib.h> /* malloc, free, qsort */ #include <stdlib.h> /* malloc, free, qsort */
#include <string.h> /* memcpy, memset */ #include <string.h> /* memcpy, memset */
@ -1499,7 +1499,7 @@ MEM_STATIC unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr)
typedef U32 DTable_max_t[FSE_DTABLE_SIZE_U32(FSE_MAX_TABLELOG)]; typedef U32 DTable_max_t[FSE_DTABLE_SIZE_U32(FSE_MAX_TABLELOG)];
/* ************************************************************** /*-**************************************************************
* Templates * Templates
****************************************************************/ ****************************************************************/
/* /*
@ -4249,39 +4249,32 @@ static size_t ZBUFF_decompressContinue(ZBUFF_DCtx* zbc, void* dst, size_t* maxDs
ip += headerSize; ip += headerSize;
headerSize = ZSTD_getFrameParams(&(zbc->params), zbc->headerBuffer, zbc->hPos); headerSize = ZSTD_getFrameParams(&(zbc->params), zbc->headerBuffer, zbc->hPos);
if (ZSTD_isError(headerSize)) return headerSize; if (ZSTD_isError(headerSize)) return headerSize;
if (headerSize) if (headerSize) {
{
/* not enough input to decode header : tell how many bytes would be necessary */ /* not enough input to decode header : tell how many bytes would be necessary */
*maxDstSizePtr = 0; *maxDstSizePtr = 0;
return headerSize - zbc->hPos; return headerSize - zbc->hPos;
} } }
// zbc->stage = ZBUFFds_decodeHeader; break; /* useless : stage follows */
}
case ZBUFFds_decodeHeader: case ZBUFFds_decodeHeader:
/* apply header to create / resize buffers */ /* apply header to create / resize buffers */
{ {
size_t neededOutSize = (size_t)1 << zbc->params.windowLog; size_t neededOutSize = (size_t)1 << zbc->params.windowLog;
size_t neededInSize = BLOCKSIZE; /* a block is never > BLOCKSIZE */ size_t neededInSize = BLOCKSIZE; /* a block is never > BLOCKSIZE */
if (zbc->inBuffSize < neededInSize) if (zbc->inBuffSize < neededInSize) {
{
free(zbc->inBuff); free(zbc->inBuff);
zbc->inBuffSize = neededInSize; zbc->inBuffSize = neededInSize;
zbc->inBuff = (char*)malloc(neededInSize); zbc->inBuff = (char*)malloc(neededInSize);
if (zbc->inBuff == NULL) return ERROR(memory_allocation); if (zbc->inBuff == NULL) return ERROR(memory_allocation);
} }
if (zbc->outBuffSize < neededOutSize) if (zbc->outBuffSize < neededOutSize) {
{
free(zbc->outBuff); free(zbc->outBuff);
zbc->outBuffSize = neededOutSize; zbc->outBuffSize = neededOutSize;
zbc->outBuff = (char*)malloc(neededOutSize); zbc->outBuff = (char*)malloc(neededOutSize);
if (zbc->outBuff == NULL) return ERROR(memory_allocation); if (zbc->outBuff == NULL) return ERROR(memory_allocation);
} } }
}
if (zbc->dictSize) if (zbc->dictSize)
ZSTD_decompress_insertDictionary(zbc->zc, zbc->dict, zbc->dictSize); ZSTD_decompress_insertDictionary(zbc->zc, zbc->dict, zbc->dictSize);
if (zbc->hPos) if (zbc->hPos) {
{
/* some data already loaded into headerBuffer : transfer into inBuff */ /* some data already loaded into headerBuffer : transfer into inBuff */
memcpy(zbc->inBuff, zbc->headerBuffer, zbc->hPos); memcpy(zbc->inBuff, zbc->headerBuffer, zbc->hPos);
zbc->inPos = zbc->hPos; zbc->inPos = zbc->hPos;

View File

@ -86,7 +86,7 @@ extern "C" {
/*-************************************************************** /*-**************************************************************
* Memory I/O * Memory I/O
*****************************************************************/ *****************************************************************/
/*!MEM_FORCE_MEMORY_ACCESS /* MEM_FORCE_MEMORY_ACCESS :
* By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable. * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
* Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal. * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
* The below switch allow to select different access method for improved performance. * The below switch allow to select different access method for improved performance.
@ -178,7 +178,7 @@ MEM_STATIC void MEM_write64(void* memPtr, U64 value)
memcpy(memPtr, &value, sizeof(value)); memcpy(memPtr, &value, sizeof(value));
} }
#endif // MEM_FORCE_MEMORY_ACCESS #endif /* MEM_FORCE_MEMORY_ACCESS */
MEM_STATIC U16 MEM_readLE16(const void* memPtr) MEM_STATIC U16 MEM_readLE16(const void* memPtr)

View File

@ -1043,8 +1043,7 @@ void ZSTD_compressBlock_fast_generic(ZSTD_CCtx* zc,
continue; /* faster when present ... (?) */ continue; /* faster when present ... (?) */
} } } } } }
/* Last Literals */ { /* Last Literals */
{
size_t lastLLSize = iend - anchor; size_t lastLLSize = iend - anchor;
memcpy(seqStorePtr->lit, anchor, lastLLSize); memcpy(seqStorePtr->lit, anchor, lastLLSize);
seqStorePtr->lit += lastLLSize; seqStorePtr->lit += lastLLSize;

View File

@ -481,27 +481,27 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
} }
best_mlen = (last_pos) ? last_pos : MINMATCH; best_mlen = (last_pos) ? last_pos : MINMATCH;
if (faster_get_matches && last_pos) if (faster_get_matches && last_pos)
match_num = 0; match_num = 0;
else else
match_num = getAllMatches(ctx, ip, ip, iend, maxSearches, mls, matches, best_mlen); /* first search (depth 0) */ match_num = getAllMatches(ctx, ip, ip, iend, maxSearches, mls, matches, best_mlen); /* first search (depth 0) */
ZSTD_LOG_PARSER("%d: match_num=%d last_pos=%d\n", (int)(ip-base), match_num, last_pos); ZSTD_LOG_PARSER("%d: match_num=%d last_pos=%d\n", (int)(ip-base), match_num, last_pos);
if (!last_pos && !match_num) { ip++; continue; } if (!last_pos && !match_num) { ip++; continue; }
opt[0].rep = rep_1; opt[0].rep = rep_1;
opt[0].rep2 = rep_2; opt[0].rep2 = rep_2;
opt[0].mlen = 1; opt[0].mlen = 1;
if (match_num && matches[match_num-1].len > sufficient_len) { if (match_num && matches[match_num-1].len > sufficient_len) {
best_mlen = matches[match_num-1].len; best_mlen = matches[match_num-1].len;
best_off = matches[match_num-1].off; best_off = matches[match_num-1].off;
cur = 0; cur = 0;
last_pos = 1; last_pos = 1;
goto _storeSequence; goto _storeSequence;
} }
// set prices using matches at position = 0 // set prices using matches at position = 0
for (u = 0; u < match_num; u++) { for (u = 0; u < match_num; u++) {
@ -523,8 +523,7 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
// check further positions // check further positions
for (skip_num = 0, cur = 1; cur <= last_pos; cur++) for (skip_num = 0, cur = 1; cur <= last_pos; cur++) {
{
size_t cur_rep; size_t cur_rep;
inr = ip + cur; inr = ip + cur;
@ -548,7 +547,7 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
if (cur == last_pos) break; if (cur == last_pos) break;
if (inr > ilimit) // last match must start at a minimum distance of 8 from oend if (inr > ilimit) /* last match must start at a minimum distance of 8 from oend */
continue; continue;
mlen = opt[cur].mlen; mlen = opt[cur].mlen;
@ -582,15 +581,15 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
if (MEM_read32(inr) == MEM_read32(inr - cur_rep)) { // check rep if (MEM_read32(inr) == MEM_read32(inr - cur_rep)) { // check rep
mlen = (U32)ZSTD_count(inr+MINMATCH, inr+MINMATCH - cur_rep, iend) + MINMATCH; mlen = (U32)ZSTD_count(inr+MINMATCH, inr+MINMATCH - cur_rep, iend) + MINMATCH;
ZSTD_LOG_PARSER("%d: Found REP mlen=%d off=%d rep=%d opt[%d].off=%d\n", (int)(inr-base), mlen, 0, opt[cur].rep, cur, opt[cur].off); ZSTD_LOG_PARSER("%d: Found REP mlen=%d off=%d rep=%d opt[%d].off=%d\n", (int)(inr-base), mlen, 0, opt[cur].rep, cur, opt[cur].off);
if (mlen > sufficient_len || cur + mlen >= ZSTD_OPT_NUM) { if (mlen > sufficient_len || cur + mlen >= ZSTD_OPT_NUM) {
best_mlen = mlen; best_mlen = mlen;
best_off = 0; best_off = 0;
ZSTD_LOG_PARSER("%d: REP sufficient_len=%d best_mlen=%d best_off=%d last_pos=%d\n", (int)(inr-base), sufficient_len, best_mlen, best_off, last_pos); ZSTD_LOG_PARSER("%d: REP sufficient_len=%d best_mlen=%d best_off=%d last_pos=%d\n", (int)(inr-base), sufficient_len, best_mlen, best_off, last_pos);
last_pos = cur + 1; last_pos = cur + 1;
goto _storeSequence; goto _storeSequence;
} }
if (opt[cur].mlen == 1) { if (opt[cur].mlen == 1) {
@ -622,13 +621,11 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
if (faster_get_matches && skip_num > 0) { skip_num--; continue; } if (faster_get_matches && skip_num > 0) { skip_num--; continue; }
best_mlen = (best_mlen > MINMATCH) ? best_mlen : MINMATCH; best_mlen = (best_mlen > MINMATCH) ? best_mlen : MINMATCH;
match_num = getAllMatches(ctx, inr, ip, iend, maxSearches, mls, matches, best_mlen); match_num = getAllMatches(ctx, inr, ip, iend, maxSearches, mls, matches, best_mlen);
ZSTD_LOG_PARSER("%d: ZSTD_GetAllMatches match_num=%d\n", (int)(inr-base), match_num); ZSTD_LOG_PARSER("%d: ZSTD_GetAllMatches match_num=%d\n", (int)(inr-base), match_num);
if (match_num > 0 && matches[match_num-1].len > sufficient_len) { if (match_num > 0 && matches[match_num-1].len > sufficient_len) {
cur -= matches[match_num-1].back; cur -= matches[match_num-1].back;
best_mlen = matches[match_num-1].len; best_mlen = matches[match_num-1].len;
@ -637,7 +634,6 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
goto _storeSequence; goto _storeSequence;
} }
/* set prices using matches at position = cur */ /* set prices using matches at position = cur */
for (u = 0; u < match_num; u++) { for (u = 0; u < match_num; u++) {
mlen = (u>0) ? matches[u-1].len+1 : best_mlen; mlen = (u>0) ? matches[u-1].len+1 : best_mlen;
@ -667,9 +663,7 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
SET_PRICE(cur2 + mlen, mlen, matches[u].off, litlen, price); SET_PRICE(cur2 + mlen, mlen, matches[u].off, litlen, price);
mlen++; mlen++;
} } } } } // for (skip_num = 0, cur = 1; cur <= last_pos; cur++)
} // for (skip_num = 0, cur = 1; cur <= last_pos; cur++)
best_mlen = opt[last_pos].mlen; best_mlen = opt[last_pos].mlen;
best_off = opt[last_pos].off; best_off = opt[last_pos].off;
@ -703,34 +697,25 @@ _storeSequence: // cur, last_pos, best_mlen, best_off have to be set
u += opt[u].mlen; u += opt[u].mlen;
} }
cur = 0; for (cur=0; cur < last_pos; ) {
while (cur < last_pos)
{
ZSTD_LOG_PARSER("%d: price3[%d/%d]=%d off=%d mlen=%d litlen=%d rep=%d rep2=%d\n", (int)(ip-base+cur), cur, last_pos, opt[cur].price, opt[cur].off, opt[cur].mlen, opt[cur].litlen, opt[cur].rep, opt[cur].rep2); ZSTD_LOG_PARSER("%d: price3[%d/%d]=%d off=%d mlen=%d litlen=%d rep=%d rep2=%d\n", (int)(ip-base+cur), cur, last_pos, opt[cur].price, opt[cur].off, opt[cur].mlen, opt[cur].litlen, opt[cur].rep, opt[cur].rep2);
mlen = opt[cur].mlen; mlen = opt[cur].mlen;
if (mlen == 1) { ip++; cur++; continue; } if (mlen == 1) { ip++; cur++; continue; }
offset = opt[cur].off; offset = opt[cur].off;
cur += mlen; cur += mlen;
U32 litLength = (U32)(ip - anchor); U32 litLength = (U32)(ip - anchor);
ZSTD_LOG_ENCODE("%d/%d: ENCODE1 literals=%d mlen=%d off=%d rep1=%d rep2=%d\n", (int)(ip-base), (int)(iend-base), (int)(litLength), (int)mlen, (int)(offset), (int)rep_1, (int)rep_2); ZSTD_LOG_ENCODE("%d/%d: ENCODE1 literals=%d mlen=%d off=%d rep1=%d rep2=%d\n", (int)(ip-base), (int)(iend-base), (int)(litLength), (int)mlen, (int)(offset), (int)rep_1, (int)rep_2);
if (offset) if (offset) {
{
rep_2 = rep_1; rep_2 = rep_1;
rep_1 = offset; rep_1 = offset;
} } else {
else if (litLength == 0) {
{
if (litLength == 0)
{
best_off = rep_2; best_off = rep_2;
rep_2 = rep_1; rep_2 = rep_1;
rep_1 = best_off; rep_1 = best_off;
} } }
}
ZSTD_LOG_ENCODE("%d/%d: ENCODE2 literals=%d mlen=%d off=%d rep1=%d rep2=%d\n", (int)(ip-base), (int)(iend-base), (int)(litLength), (int)mlen, (int)(offset), (int)rep_1, (int)rep_2); ZSTD_LOG_ENCODE("%d/%d: ENCODE2 literals=%d mlen=%d off=%d rep1=%d rep2=%d\n", (int)(ip-base), (int)(iend-base), (int)(litLength), (int)mlen, (int)(offset), (int)rep_1, (int)rep_2);
@ -759,8 +744,7 @@ _storeSequence: // cur, last_pos, best_mlen, best_off have to be set
anchor = ip = ip + mlen; anchor = ip = ip + mlen;
} }
/* check immediate repcode */
// check immediate repcode
while ( (anchor <= ilimit) while ( (anchor <= ilimit)
&& (MEM_read32(anchor) == MEM_read32(anchor - rep_2)) ) { && (MEM_read32(anchor) == MEM_read32(anchor - rep_2)) ) {
/* store sequence */ /* store sequence */
@ -774,13 +758,11 @@ _storeSequence: // cur, last_pos, best_mlen, best_off have to be set
anchor += best_mlen+MINMATCH; anchor += best_mlen+MINMATCH;
ip = anchor; ip = anchor;
continue; // faster when present ... (?) continue; // faster when present ... (?)
} } }
}
/* Last Literals */ { /* Last Literals */
{ size_t lastLLSize = iend - anchor;
U32 lastLLSize = (U32)(iend - anchor); ZSTD_LOG_ENCODE("%d: lastLLSize literals=%u\n", (int)(ip-base), (U32)lastLLSize);
ZSTD_LOG_ENCODE("%d: lastLLSize literals=%d\n", (int)(ip-base), (int)(lastLLSize));
memcpy(seqStorePtr->lit, anchor, lastLLSize); memcpy(seqStorePtr->lit, anchor, lastLLSize);
seqStorePtr->lit += lastLLSize; seqStorePtr->lit += lastLLSize;
} }
@ -826,21 +808,16 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
ZSTD_resetSeqStore(seqStorePtr); ZSTD_resetSeqStore(seqStorePtr);
if ((ip - prefixStart) < REPCODE_STARTVALUE) ip += REPCODE_STARTVALUE; if ((ip - prefixStart) < REPCODE_STARTVALUE) ip += REPCODE_STARTVALUE;
/* Match Loop */ /* Match Loop */
while (ip < ilimit) { while (ip < ilimit) {
U32 u; U32 u, offset, best_off=0;
U32 offset; U32 mlen=0, best_mlen=0;
U32 mlen=0;
U32 best_mlen=0;
U32 best_off=0;
U32 current = (U32)(ip-base); U32 current = (U32)(ip-base);
memset(opt, 0, sizeof(ZSTD_optimal_t)); memset(opt, 0, sizeof(ZSTD_optimal_t));
last_pos = 0; last_pos = 0;
inr = ip; inr = ip;
opt[0].litlen = (U32)(ip - anchor); opt[0].litlen = (U32)(ip - anchor);
/* check repCode */ /* check repCode */
{ {
const U32 repIndex = (U32)(current+1 - rep_1); const U32 repIndex = (U32)(current+1 - rep_1);
@ -872,7 +849,7 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
if (faster_get_matches && last_pos) if (faster_get_matches && last_pos)
match_num = 0; match_num = 0;
else else
match_num = getAllMatches(ctx, ip, ip, iend, maxSearches, mls, matches, best_mlen); /* first search (depth 0) */ match_num = getAllMatches(ctx, ip, ip, iend, maxSearches, mls, matches, best_mlen); /* first search (depth 0) */
ZSTD_LOG_PARSER("%d: match_num=%d last_pos=%d\n", (int)(ip-base), match_num, last_pos); ZSTD_LOG_PARSER("%d: match_num=%d last_pos=%d\n", (int)(ip-base), match_num, last_pos);
if (!last_pos && !match_num) { ip++; continue; } if (!last_pos && !match_num) { ip++; continue; }
@ -907,8 +884,7 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
ip++; continue; ip++; continue;
} }
/* check further positions */
// check further positions
for (skip_num = 0, cur = 1; cur <= last_pos; cur++) { for (skip_num = 0, cur = 1; cur <= last_pos; cur++) {
size_t cur_rep; size_t cur_rep;
inr = ip + cur; inr = ip + cur;
@ -955,8 +931,6 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
ZSTD_LOG_PARSER("%d: CURRENT price[%d/%d]=%d off=%d mlen=%d litlen=%d rep=%d rep2=%d\n", (int)(inr-base), cur, last_pos, opt[cur].price, opt[cur].off, opt[cur].mlen, opt[cur].litlen, opt[cur].rep, opt[cur].rep2); ZSTD_LOG_PARSER("%d: CURRENT price[%d/%d]=%d off=%d mlen=%d litlen=%d rep=%d rep2=%d\n", (int)(inr-base), cur, last_pos, opt[cur].price, opt[cur].off, opt[cur].mlen, opt[cur].litlen, opt[cur].rep, opt[cur].rep2);
best_mlen = 0; best_mlen = 0;
if (!opt[cur].off && opt[cur].mlen != 1) { if (!opt[cur].off && opt[cur].mlen != 1) {
@ -970,8 +944,8 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
const U32 repIndex = (U32)(current+cur - cur_rep); const U32 repIndex = (U32)(current+cur - cur_rep);
const BYTE* const repBase = repIndex < dictLimit ? dictBase : base; const BYTE* const repBase = repIndex < dictLimit ? dictBase : base;
const BYTE* const repMatch = repBase + repIndex; const BYTE* const repMatch = repBase + repIndex;
if ((U32)((dictLimit-1) - repIndex) >= 3) /* intentional overflow */ if ( ((U32)((dictLimit-1) - repIndex) >= 3) /* intentional overflow */
if (MEM_read32(inr) == MEM_read32(repMatch)) { &&(MEM_read32(inr) == MEM_read32(repMatch)) ) {
/* repcode detected */ /* repcode detected */
const BYTE* const repEnd = repIndex < dictLimit ? dictEnd : iend; const BYTE* const repEnd = repIndex < dictLimit ? dictEnd : iend;
mlen = (U32)ZSTD_count_2segments(inr+MINMATCH, repMatch+MINMATCH, iend, repEnd, prefixStart) + MINMATCH; mlen = (U32)ZSTD_count_2segments(inr+MINMATCH, repMatch+MINMATCH, iend, repEnd, prefixStart) + MINMATCH;
@ -983,11 +957,10 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
ZSTD_LOG_PARSER("%d: REP sufficient_len=%d best_mlen=%d best_off=%d last_pos=%d\n", (int)(inr-base), sufficient_len, best_mlen, best_off, last_pos); ZSTD_LOG_PARSER("%d: REP sufficient_len=%d best_mlen=%d best_off=%d last_pos=%d\n", (int)(inr-base), sufficient_len, best_mlen, best_off, last_pos);
last_pos = cur + 1; last_pos = cur + 1;
goto _storeSequence; goto _storeSequence;
} }
if (opt[cur].mlen == 1) { if (opt[cur].mlen == 1) {
litlen = opt[cur].litlen; litlen = opt[cur].litlen;
if (cur > litlen) { if (cur > litlen) {
price = opt[cur - litlen].price + ZSTD_getPrice(seqStorePtr, litlen, inr-litlen, 0, mlen - MINMATCH); price = opt[cur - litlen].price + ZSTD_getPrice(seqStorePtr, litlen, inr-litlen, 0, mlen - MINMATCH);
ZSTD_LOG_TRY_PRICE("%d: TRY5 opt[%d].price=%d price=%d cur=%d litlen=%d\n", (int)(inr-base), cur - litlen, opt[cur - litlen].price, price, cur, litlen); ZSTD_LOG_TRY_PRICE("%d: TRY5 opt[%d].price=%d price=%d cur=%d litlen=%d\n", (int)(inr-base), cur - litlen, opt[cur - litlen].price, price, cur, litlen);
@ -1000,8 +973,7 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
} }
best_mlen = mlen; best_mlen = mlen;
if (faster_get_matches) if (faster_get_matches) skip_num = best_mlen;
skip_num = best_mlen;
ZSTD_LOG_PARSER("%d: Found REP mlen=%d off=%d price=%d litlen=%d price[%d]=%d\n", (int)(inr-base), mlen, 0, price, litlen, cur - litlen, opt[cur - litlen].price); ZSTD_LOG_PARSER("%d: Found REP mlen=%d off=%d price=%d litlen=%d price[%d]=%d\n", (int)(inr-base), mlen, 0, price, litlen, cur - litlen, opt[cur - litlen].price);
@ -1012,7 +984,6 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
} while (mlen >= MINMATCH); } while (mlen >= MINMATCH);
} }
if (faster_get_matches && skip_num > 0) { skip_num--; continue; } if (faster_get_matches && skip_num > 0) { skip_num--; continue; }
best_mlen = (best_mlen > MINMATCH) ? best_mlen : MINMATCH; best_mlen = (best_mlen > MINMATCH) ? best_mlen : MINMATCH;
@ -1020,7 +991,6 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
match_num = getAllMatches(ctx, inr, ip, iend, maxSearches, mls, matches, best_mlen); match_num = getAllMatches(ctx, inr, ip, iend, maxSearches, mls, matches, best_mlen);
ZSTD_LOG_PARSER("%d: ZSTD_GetAllMatches match_num=%d\n", (int)(inr-base), match_num); ZSTD_LOG_PARSER("%d: ZSTD_GetAllMatches match_num=%d\n", (int)(inr-base), match_num);
if (match_num > 0 && matches[match_num-1].len > sufficient_len) { if (match_num > 0 && matches[match_num-1].len > sufficient_len) {
cur -= matches[match_num-1].back; cur -= matches[match_num-1].back;
best_mlen = matches[match_num-1].len; best_mlen = matches[match_num-1].len;
@ -1029,7 +999,6 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
goto _storeSequence; goto _storeSequence;
} }
// set prices using matches at position = cur // set prices using matches at position = cur
for (u = 0; u < match_num; u++) { for (u = 0; u < match_num; u++) {
mlen = (u>0) ? matches[u-1].len+1 : best_mlen; mlen = (u>0) ? matches[u-1].len+1 : best_mlen;
@ -1059,9 +1028,7 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
SET_PRICE(cur2 + mlen, mlen, matches[u].off, litlen, price); SET_PRICE(cur2 + mlen, mlen, matches[u].off, litlen, price);
mlen++; mlen++;
} } } } } // for (skip_num = 0, cur = 1; cur <= last_pos; cur++)
} // for (skip_num = 0, cur = 1; cur <= last_pos; cur++)
best_mlen = opt[last_pos].mlen; best_mlen = opt[last_pos].mlen;
best_off = opt[last_pos].off; best_off = opt[last_pos].off;
@ -1084,8 +1051,7 @@ _storeSequence: // cur, last_pos, best_mlen, best_off have to be set
opt[cur].off = best_off; opt[cur].off = best_off;
best_mlen = mlen; best_mlen = mlen;
best_off = offset; best_off = offset;
if (mlen > cur) if (mlen > cur) break;
break;
cur -= mlen; cur -= mlen;
} }
@ -1144,7 +1110,6 @@ _storeSequence: // cur, last_pos, best_mlen, best_off have to be set
anchor = ip = ip + mlen; anchor = ip = ip + mlen;
} }
/* check immediate repcode */ /* check immediate repcode */
while (anchor <= ilimit) { while (anchor <= ilimit) {
const U32 repIndex = (U32)((anchor-base) - rep_2); const U32 repIndex = (U32)((anchor-base) - rep_2);
@ -1166,10 +1131,9 @@ _storeSequence: // cur, last_pos, best_mlen, best_off have to be set
break; break;
} } } }
/* Last Literals */ { /* Last Literals */
{ size_t lastLLSize = iend - anchor;
U32 lastLLSize = (U32)(iend - anchor); ZSTD_LOG_ENCODE("%d: lastLLSize literals=%u\n", (int)(ip-base), (U32)(lastLLSize));
ZSTD_LOG_ENCODE("%d: lastLLSize literals=%d\n", (int)(ip-base), (int)(lastLLSize));
memcpy(seqStorePtr->lit, anchor, lastLLSize); memcpy(seqStorePtr->lit, anchor, lastLLSize);
seqStorePtr->lit += lastLLSize; seqStorePtr->lit += lastLLSize;
} }

View File

@ -1,6 +1,6 @@
/* /*
fileio.c - File i/o handler fileio.c - File i/o handler for zstd
Copyright (C) Yann Collet 2013-2015 Copyright (C) Yann Collet 2013-2016
GPL v2 License GPL v2 License
@ -19,8 +19,7 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
You can contact the author at : You can contact the author at :
- zstd source repository : https://github.com/Cyan4973/zstd - zstd homepage : http://www.zstd.net
- Public forum : https://groups.google.com/forum/#!forum/lz4c
*/ */
/* /*
Note : this is stand-alone program. Note : this is stand-alone program.
@ -33,7 +32,7 @@
* Tuning options * Tuning options
***************************************/ ***************************************/
#ifndef ZSTD_LEGACY_SUPPORT #ifndef ZSTD_LEGACY_SUPPORT
/**LEGACY_SUPPORT : /* LEGACY_SUPPORT :
* decompressor can decode older formats (starting from Zstd 0.1+) */ * decompressor can decode older formats (starting from Zstd 0.1+) */
# define ZSTD_LEGACY_SUPPORT 1 # define ZSTD_LEGACY_SUPPORT 1
#endif #endif
@ -80,9 +79,6 @@
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
# include <fcntl.h> /* _O_BINARY */ # include <fcntl.h> /* _O_BINARY */
# include <io.h> /* _setmode, _isatty */ # include <io.h> /* _setmode, _isatty */
# ifdef __MINGW32__
// int _fileno(FILE *stream); /* seems no longer useful /* MINGW somehow forgets to include this windows declaration into <stdio.h> */
# endif
# define SET_BINARY_MODE(file) { int unused = _setmode(_fileno(file), _O_BINARY); (void)unused; } # define SET_BINARY_MODE(file) { int unused = _setmode(_fileno(file), _O_BINARY); (void)unused; }
# define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream)) # define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream))
#else #else
@ -317,10 +313,10 @@ static void FIO_freeCResources(cRess_t ress)
} }
/* /*!
* FIO_compressFilename_extRess() * FIO_compressFilename_extRess() :
* result : 0 : compression completed correctly * @result : 0 : compression completed correctly,
* 1 : missing or pb opening srcFileName * 1 : missing or pb opening srcFileName
*/ */
static int FIO_compressFilename_extRess(cRess_t ress, static int FIO_compressFilename_extRess(cRess_t ress,
const char* dstFileName, const char* srcFileName, const char* dstFileName, const char* srcFileName,

View File

@ -175,7 +175,7 @@ static U64 XXH_read64(const void* memPtr)
return val; return val;
} }
#endif // XXH_FORCE_DIRECT_MEMORY_ACCESS #endif /* XXH_FORCE_DIRECT_MEMORY_ACCESS */
/* **************************************** /* ****************************************

View File

@ -1,6 +1,6 @@
/* /*
zstdcli - Command Line Interface (cli) for zstd zstdcli - Command Line Interface (cli) for zstd
Copyright (C) Yann Collet 2014-2015 Copyright (C) Yann Collet 2014-2016
GPL v2 License GPL v2 License
@ -19,8 +19,7 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
You can contact the author at : You can contact the author at :
- zstd source repository : https://github.com/Cyan4973/zstd - zstd homepage : http://www.zstd.net/
- ztsd public forum : https://groups.google.com/forum/#!forum/lz4c
*/ */
/* /*
Note : this is user program. Note : this is user program.
@ -30,14 +29,14 @@
*/ */
/************************************** /*-************************************
* Compiler Options * Compiler Options
**************************************/ **************************************/
#define _CRT_SECURE_NO_WARNINGS /* Visual : removes warning from strcpy */ #define _CRT_SECURE_NO_WARNINGS /* Visual : removes warning from strcpy */
#define _POSIX_SOURCE 1 /* triggers fileno() within <stdio.h> on unix */ #define _POSIX_SOURCE 1 /* triggers fileno() within <stdio.h> on unix */
/************************************** /*-************************************
* Includes * Includes
**************************************/ **************************************/
#include <stdio.h> /* fprintf, getchar */ #include <stdio.h> /* fprintf, getchar */
@ -50,7 +49,7 @@
#include "zstd.h" /* ZSTD version numbers */ #include "zstd.h" /* ZSTD version numbers */
/************************************** /*-************************************
* OS-specific Includes * OS-specific Includes
**************************************/ **************************************/
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
@ -68,7 +67,7 @@
#endif #endif
/************************************** /*-************************************
* Constants * Constants
**************************************/ **************************************/
#define COMPRESSOR_NAME "zstd command line interface" #define COMPRESSOR_NAME "zstd command line interface"
@ -88,16 +87,16 @@
#define GB *(1U<<30) #define GB *(1U<<30)
/************************************** /*-************************************
* Display Macros * Display Macros
**************************************/ **************************************/
#define DISPLAY(...) fprintf(displayOut, __VA_ARGS__) #define DISPLAY(...) fprintf(displayOut, __VA_ARGS__)
#define DISPLAYLEVEL(l, ...) if (displayLevel>=l) { DISPLAY(__VA_ARGS__); } #define DISPLAYLEVEL(l, ...) if (displayLevel>=l) { DISPLAY(__VA_ARGS__); }
static FILE* displayOut; static FILE* displayOut;
static unsigned displayLevel = 2; // 0 : no display // 1: errors // 2 : + result + interaction + warnings ; // 3 : + progression; // 4 : + information static unsigned displayLevel = 2; /* 0 : no display, 1: errors, 2 : + result + interaction + warnings, 3 : + progression, 4 : + information */
/************************************** /*-************************************
* Exceptions * Exceptions
**************************************/ **************************************/
#define DEBUG 0 #define DEBUG 0
@ -112,7 +111,7 @@ static unsigned displayLevel = 2; // 0 : no display // 1: errors // 2 : + re
} }
/************************************** /*-************************************
* Command Line * Command Line
**************************************/ **************************************/
static int usage(const char* programName) static int usage(const char* programName)
@ -126,7 +125,6 @@ static int usage(const char* programName)
DISPLAY( " -# : # compression level (1-19, default:1) \n"); DISPLAY( " -# : # compression level (1-19, default:1) \n");
DISPLAY( " -d : decompression \n"); DISPLAY( " -d : decompression \n");
DISPLAY( " -D file: use `file` as Dictionary \n"); DISPLAY( " -D file: use `file` as Dictionary \n");
//DISPLAY( " -z : force compression\n");
DISPLAY( " -f : overwrite output without prompting \n"); DISPLAY( " -f : overwrite output without prompting \n");
DISPLAY( " -h/-H : display help/long help and exit\n"); DISPLAY( " -h/-H : display help/long help and exit\n");
return 0; return 0;
@ -203,10 +201,8 @@ int main(int argCount, const char** argv)
if (!strcmp(programName, ZSTD_CAT)) { decode=1; forceStdout=1; displayLevel=1; outFileName=stdoutmark; } if (!strcmp(programName, ZSTD_CAT)) { decode=1; forceStdout=1; displayLevel=1; outFileName=stdoutmark; }
/* command switches */ /* command switches */
for(i=1; i<argCount; i++) for(i=1; i<argCount; i++) {
{
const char* argument = argv[i]; const char* argument = argv[i];
if(!argument) continue; /* Protection if argument empty */ if(!argument) continue; /* Protection if argument empty */
/* long commands (--long-word) */ /* long commands (--long-word) */
@ -217,11 +213,9 @@ int main(int argCount, const char** argv)
if (!strcmp(argument, "--quiet")) { displayLevel--; continue; } if (!strcmp(argument, "--quiet")) { displayLevel--; continue; }
/* Decode commands (note : aggregated commands are allowed) */ /* Decode commands (note : aggregated commands are allowed) */
if (argument[0]=='-') if (argument[0]=='-') {
{
/* '-' means stdin/stdout */ /* '-' means stdin/stdout */
if (argument[1]==0) if (argument[1]==0) {
{
if (!filenameIdx) { filenameIdx=1, filenameTable[0]=stdinmark; continue; } if (!filenameIdx) { filenameIdx=1, filenameTable[0]=stdinmark; continue; }
outFileName=stdoutmark; continue; outFileName=stdoutmark; continue;
} }
@ -250,10 +244,7 @@ int main(int argCount, const char** argv)
case 'H': case 'H':
case 'h': displayOut=stdout; return usage_advanced(programName); case 'h': displayOut=stdout; return usage_advanced(programName);
/* Compression (default) */ /* Decoding */
//case 'z': forceCompress = 1; break;
/* Decoding */
case 'd': decode=1; argument++; break; case 'd': decode=1; argument++; break;
/* Multiple input files */ /* Multiple input files */
@ -265,9 +256,6 @@ int main(int argCount, const char** argv)
/* Use file content as dictionary */ /* Use file content as dictionary */
case 'D': nextEntryIsDictionary = 1; argument++; break; case 'D': nextEntryIsDictionary = 1; argument++; break;
/* Test -- not implemented */
/* case 't': decode=1; LZ4IO_setOverwrite(1); output_filename=nulmark; break; */
/* Overwrite */ /* Overwrite */
case 'f': FIO_overwriteMode(); argument++; break; case 'f': FIO_overwriteMode(); argument++; break;
@ -327,8 +315,7 @@ int main(int argCount, const char** argv)
} }
/* dictionary */ /* dictionary */
if (nextEntryIsDictionary) if (nextEntryIsDictionary) {
{
nextEntryIsDictionary = 0; nextEntryIsDictionary = 0;
dictFileName = argument; dictFileName = argument;
continue; continue;
@ -342,8 +329,7 @@ int main(int argCount, const char** argv)
DISPLAYLEVEL(3, WELCOME_MESSAGE); DISPLAYLEVEL(3, WELCOME_MESSAGE);
/* Check if benchmark is selected */ /* Check if benchmark is selected */
if (bench) if (bench) {
{
#ifndef ZSTD_NOBENCH #ifndef ZSTD_NOBENCH
BMK_benchFiles(filenameTable, filenameIdx, dictFileName, cLevel*rangeBench); BMK_benchFiles(filenameTable, filenameIdx, dictFileName, cLevel*rangeBench);
#endif #endif
@ -358,11 +344,9 @@ int main(int argCount, const char** argv)
/* No output filename ==> try to select one automatically (when possible) */ /* No output filename ==> try to select one automatically (when possible) */
if (filenameIdx>=2) outFileName = filenameTable[1]; if (filenameIdx>=2) outFileName = filenameTable[1];
while (!outFileName) /* while : just to allow break statement */ while (!outFileName) { /* while : just to allow break statement */
{
if (!IS_CONSOLE(stdout)) { outFileName=stdoutmark; break; } /* Default to stdout whenever possible (i.e. not a console) */ if (!IS_CONSOLE(stdout)) { outFileName=stdoutmark; break; } /* Default to stdout whenever possible (i.e. not a console) */
if (!decode) /* compression to file */ if (!decode) { /* compression to file */
{
size_t l = strlen(filenameTable[0]); size_t l = strlen(filenameTable[0]);
dynNameSpace = (char*)calloc(1,l+5); dynNameSpace = (char*)calloc(1,l+5);
if (dynNameSpace==NULL) { DISPLAY("not enough memory\n"); exit(1); } if (dynNameSpace==NULL) { DISPLAY("not enough memory\n"); exit(1); }
@ -375,8 +359,7 @@ int main(int argCount, const char** argv)
/* decompression to file (automatic name will work only if input filename has correct format extension) */ /* decompression to file (automatic name will work only if input filename has correct format extension) */
{ {
size_t filenameSize = strlen(filenameTable[0]); size_t filenameSize = strlen(filenameTable[0]);
if (strcmp(filenameTable[0] + (filenameSize-4), extension)) if (strcmp(filenameTable[0] + (filenameSize-4), extension)) {
{
DISPLAYLEVEL(1, "unknown suffix - cannot determine destination filename\n"); DISPLAYLEVEL(1, "unknown suffix - cannot determine destination filename\n");
return badusage(programName); return badusage(programName);
} }
@ -386,8 +369,7 @@ int main(int argCount, const char** argv)
strcpy(dynNameSpace, filenameTable[0]); strcpy(dynNameSpace, filenameTable[0]);
dynNameSpace[filenameSize-4]=0; dynNameSpace[filenameSize-4]=0;
DISPLAYLEVEL(2, "Decoding file %s \n", outFileName); DISPLAYLEVEL(2, "Decoding file %s \n", outFileName);
} } }
}
/* Check if output is defined as console; trigger an error in this case */ /* Check if output is defined as console; trigger an error in this case */
if (!strcmp(outFileName,stdoutmark) && IS_CONSOLE(stdout) && !forceStdout) return badusage(programName); if (!strcmp(outFileName,stdoutmark) && IS_CONSOLE(stdout) && !forceStdout) return badusage(programName);
@ -396,23 +378,19 @@ int main(int argCount, const char** argv)
if (!strcmp(filenameTable[0], stdinmark) && !strcmp(outFileName,stdoutmark) && (displayLevel==2)) displayLevel=1; if (!strcmp(filenameTable[0], stdinmark) && !strcmp(outFileName,stdoutmark) && (displayLevel==2)) displayLevel=1;
if (multiple && (displayLevel==2)) displayLevel=1; if (multiple && (displayLevel==2)) displayLevel=1;
if ((!multiple) && (filenameIdx>2)) if ((!multiple) && (filenameIdx>2)) {
{
DISPLAY("Too many files on the command line (%u > 2). Do you mean -m ? \n", filenameIdx); DISPLAY("Too many files on the command line (%u > 2). Do you mean -m ? \n", filenameIdx);
return filenameIdx; return filenameIdx;
} }
/* IO Stream/File */ /* IO Stream/File */
FIO_setNotificationLevel(displayLevel); FIO_setNotificationLevel(displayLevel);
if (decode) if (decode) {
{
if (multiple) if (multiple)
operationResult = FIO_decompressMultipleFilenames(filenameTable, filenameIdx, ZSTD_EXTENSION, dictFileName); operationResult = FIO_decompressMultipleFilenames(filenameTable, filenameIdx, ZSTD_EXTENSION, dictFileName);
else else
operationResult = FIO_decompressFilename(outFileName, filenameTable[0], dictFileName); operationResult = FIO_decompressFilename(outFileName, filenameTable[0], dictFileName);
} } else { /* compression */
else
{
if (multiple) if (multiple)
operationResult = FIO_compressMultipleFilenames(filenameTable, filenameIdx, ZSTD_EXTENSION, dictFileName, cLevel); operationResult = FIO_compressMultipleFilenames(filenameTable, filenameIdx, ZSTD_EXTENSION, dictFileName, cLevel);
else else