separate newRep() from updateRep()
the new contracts seems to make more sense : updateRep() updates an array of repeat offsets _in place_, while newRep() generates a new structure with the updated repeat-offset array. Most callers are actually expecting the in-place variant, and a limited sub-section, in `zstd_opt.c` mainly, prefer `newRep()`.
This commit is contained in:
@@ -2939,9 +2939,9 @@ static void ZSTD_copyBlockSequences(ZSTD_CCtx* zc)
|
|||||||
outSeqs[i].offset = rawOffset;
|
outSeqs[i].offset = rawOffset;
|
||||||
/* seqStoreSeqs[i].offset == offCode+1, and ZSTD_updateRep() expects offCode
|
/* seqStoreSeqs[i].offset == offCode+1, and ZSTD_updateRep() expects offCode
|
||||||
so we provide seqStoreSeqs[i].offset - 1 */
|
so we provide seqStoreSeqs[i].offset - 1 */
|
||||||
updatedRepcodes = ZSTD_updateRep(updatedRepcodes.rep,
|
ZSTD_updateRep(updatedRepcodes.rep,
|
||||||
seqStoreSeqs[i].offBase - 1,
|
seqStoreSeqs[i].offBase - 1,
|
||||||
seqStoreSeqs[i].litLength == 0);
|
seqStoreSeqs[i].litLength == 0);
|
||||||
literalsRead += outSeqs[i].litLength;
|
literalsRead += outSeqs[i].litLength;
|
||||||
}
|
}
|
||||||
/* Insert last literals (if any exist) in the block as a sequence with ml == off == 0.
|
/* Insert last literals (if any exist) in the block as a sequence with ml == off == 0.
|
||||||
@@ -3482,8 +3482,8 @@ static void ZSTD_seqStore_resolveOffCodes(repcodes_t* const dRepcodes, repcodes_
|
|||||||
/* Compression repcode history is always updated with values directly from the unmodified seqStore.
|
/* Compression repcode history is always updated with values directly from the unmodified seqStore.
|
||||||
* Decompression repcode history may use modified seq->offset value taken from compression repcode history.
|
* Decompression repcode history may use modified seq->offset value taken from compression repcode history.
|
||||||
*/
|
*/
|
||||||
*dRepcodes = ZSTD_updateRep(dRepcodes->rep, seq->offBase - 1, ll0);
|
ZSTD_updateRep(dRepcodes->rep, seq->offBase - 1, ll0);
|
||||||
*cRepcodes = ZSTD_updateRep(cRepcodes->rep, offCode, ll0);
|
ZSTD_updateRep(cRepcodes->rep, offCode, ll0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5808,7 +5808,7 @@ ZSTD_copySequencesToSeqStoreExplicitBlockDelim(ZSTD_CCtx* cctx,
|
|||||||
U32 const ll0 = (litLength == 0);
|
U32 const ll0 = (litLength == 0);
|
||||||
U32 const matchLength = inSeqs[idx].matchLength;
|
U32 const matchLength = inSeqs[idx].matchLength;
|
||||||
U32 const offCode = ZSTD_finalizeOffCode(inSeqs[idx].offset, updatedRepcodes.rep, ll0);
|
U32 const offCode = ZSTD_finalizeOffCode(inSeqs[idx].offset, updatedRepcodes.rep, ll0);
|
||||||
updatedRepcodes = ZSTD_updateRep(updatedRepcodes.rep, offCode, ll0);
|
ZSTD_updateRep(updatedRepcodes.rep, offCode, ll0);
|
||||||
|
|
||||||
DEBUGLOG(6, "Storing sequence: (of: %u, ml: %u, ll: %u)", offCode, matchLength, litLength);
|
DEBUGLOG(6, "Storing sequence: (of: %u, ml: %u, ll: %u)", offCode, matchLength, litLength);
|
||||||
if (cctx->appliedParams.validateSequences) {
|
if (cctx->appliedParams.validateSequences) {
|
||||||
@@ -5931,7 +5931,7 @@ ZSTD_copySequencesToSeqStoreNoBlockDelim(ZSTD_CCtx* cctx, ZSTD_sequencePosition*
|
|||||||
/* Check if this offset can be represented with a repcode */
|
/* Check if this offset can be represented with a repcode */
|
||||||
{ U32 const ll0 = (litLength == 0);
|
{ U32 const ll0 = (litLength == 0);
|
||||||
offCode = ZSTD_finalizeOffCode(rawOffset, updatedRepcodes.rep, ll0);
|
offCode = ZSTD_finalizeOffCode(rawOffset, updatedRepcodes.rep, ll0);
|
||||||
updatedRepcodes = ZSTD_updateRep(updatedRepcodes.rep, offCode, ll0);
|
ZSTD_updateRep(updatedRepcodes.rep, offCode, ll0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cctx->appliedParams.validateSequences) {
|
if (cctx->appliedParams.validateSequences) {
|
||||||
|
|||||||
@@ -655,32 +655,40 @@ ZSTD_storeSeq(seqStore_t* seqStorePtr,
|
|||||||
seqStorePtr->sequences++;
|
seqStorePtr->sequences++;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct repcodes_s {
|
|
||||||
U32 rep[3];
|
|
||||||
} repcodes_t;
|
|
||||||
|
|
||||||
/* ZSTD_updateRep() :
|
/* ZSTD_updateRep() :
|
||||||
* @offcode : sum-type, with same numeric representation as ZSTD_storeSeq()
|
* updates in-place @rep (array of repeat offsets)
|
||||||
|
* @offBase_minus1 : sum-type, with same numeric representation as ZSTD_storeSeq()
|
||||||
*/
|
*/
|
||||||
MEM_STATIC repcodes_t
|
MEM_STATIC void
|
||||||
ZSTD_updateRep(U32 const rep[3], U32 const offBase_minus1, U32 const ll0)
|
ZSTD_updateRep(U32 rep[ZSTD_REP_NUM], U32 const offBase_minus1, U32 const ll0)
|
||||||
{
|
{
|
||||||
repcodes_t newReps;
|
|
||||||
if (STORED_IS_OFFSET(offBase_minus1)) { /* full offset */
|
if (STORED_IS_OFFSET(offBase_minus1)) { /* full offset */
|
||||||
newReps.rep[2] = rep[1];
|
rep[2] = rep[1];
|
||||||
newReps.rep[1] = rep[0];
|
rep[1] = rep[0];
|
||||||
newReps.rep[0] = STORED_OFFSET(offBase_minus1);
|
rep[0] = STORED_OFFSET(offBase_minus1);
|
||||||
} else { /* repcode */
|
} else { /* repcode */
|
||||||
U32 const repCode = STORED_REPCODE(offBase_minus1) - 1 + ll0;
|
U32 const repCode = STORED_REPCODE(offBase_minus1) - 1 + ll0;
|
||||||
if (repCode > 0) { /* note : if repCode==0, no change */
|
if (repCode > 0) { /* note : if repCode==0, no change */
|
||||||
U32 const currentOffset = (repCode==ZSTD_REP_NUM) ? (rep[0] - 1) : rep[repCode];
|
U32 const currentOffset = (repCode==ZSTD_REP_NUM) ? (rep[0] - 1) : rep[repCode];
|
||||||
newReps.rep[2] = (repCode >= 2) ? rep[1] : rep[2];
|
rep[2] = (repCode >= 2) ? rep[1] : rep[2];
|
||||||
newReps.rep[1] = rep[0];
|
rep[1] = rep[0];
|
||||||
newReps.rep[0] = currentOffset;
|
rep[0] = currentOffset;
|
||||||
} else { /* repCode == 0 */
|
} else { /* repCode == 0 */
|
||||||
ZSTD_memcpy(&newReps, rep, sizeof(newReps));
|
/* nothing to do */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct repcodes_s {
|
||||||
|
U32 rep[3];
|
||||||
|
} repcodes_t;
|
||||||
|
|
||||||
|
MEM_STATIC repcodes_t
|
||||||
|
ZSTD_newRep(U32 const rep[ZSTD_REP_NUM], U32 const offBase_minus1, U32 const ll0)
|
||||||
|
{
|
||||||
|
repcodes_t newReps;
|
||||||
|
memcpy(&newReps, rep, sizeof(newReps));
|
||||||
|
ZSTD_updateRep(newReps.rep, offBase_minus1, ll0);
|
||||||
return newReps;
|
return newReps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -539,7 +539,7 @@ static size_t ZSTD_compressSubBlock_multi(const seqStore_t* seqStorePtr,
|
|||||||
repcodes_t rep;
|
repcodes_t rep;
|
||||||
ZSTD_memcpy(&rep, prevCBlock->rep, sizeof(rep));
|
ZSTD_memcpy(&rep, prevCBlock->rep, sizeof(rep));
|
||||||
for (seq = sstart; seq < sp; ++seq) {
|
for (seq = sstart; seq < sp; ++seq) {
|
||||||
rep = ZSTD_updateRep(rep.rep, seq->offBase - 1, ZSTD_getSequenceLength(seqStorePtr, seq).litLength == 0);
|
ZSTD_updateRep(rep.rep, seq->offBase - 1, ZSTD_getSequenceLength(seqStorePtr, seq).litLength == 0);
|
||||||
}
|
}
|
||||||
ZSTD_memcpy(nextCBlock->rep, &rep, sizeof(rep));
|
ZSTD_memcpy(nextCBlock->rep, &rep, sizeof(rep));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1164,7 +1164,7 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms,
|
|||||||
assert(cur >= opt[cur].mlen);
|
assert(cur >= opt[cur].mlen);
|
||||||
if (opt[cur].mlen != 0) {
|
if (opt[cur].mlen != 0) {
|
||||||
U32 const prev = cur - opt[cur].mlen;
|
U32 const prev = cur - opt[cur].mlen;
|
||||||
repcodes_t newReps = ZSTD_updateRep(opt[prev].rep, opt[cur].off, opt[cur].litlen==0);
|
repcodes_t const newReps = ZSTD_newRep(opt[prev].rep, opt[cur].off, opt[cur].litlen==0);
|
||||||
ZSTD_memcpy(opt[cur].rep, &newReps, sizeof(repcodes_t));
|
ZSTD_memcpy(opt[cur].rep, &newReps, sizeof(repcodes_t));
|
||||||
} else {
|
} else {
|
||||||
ZSTD_memcpy(opt[cur].rep, opt[cur - 1].rep, sizeof(repcodes_t));
|
ZSTD_memcpy(opt[cur].rep, opt[cur - 1].rep, sizeof(repcodes_t));
|
||||||
@@ -1254,7 +1254,7 @@ _shortestPath: /* cur, last_pos, best_mlen, best_off have to be set */
|
|||||||
* update them while traversing the sequences.
|
* update them while traversing the sequences.
|
||||||
*/
|
*/
|
||||||
if (lastSequence.mlen != 0) {
|
if (lastSequence.mlen != 0) {
|
||||||
repcodes_t reps = ZSTD_updateRep(opt[cur].rep, lastSequence.off, lastSequence.litlen==0);
|
repcodes_t const reps = ZSTD_newRep(opt[cur].rep, lastSequence.off, lastSequence.litlen==0);
|
||||||
ZSTD_memcpy(rep, &reps, sizeof(reps));
|
ZSTD_memcpy(rep, &reps, sizeof(reps));
|
||||||
} else {
|
} else {
|
||||||
ZSTD_memcpy(rep, opt[cur].rep, sizeof(repcodes_t));
|
ZSTD_memcpy(rep, opt[cur].rep, sizeof(repcodes_t));
|
||||||
|
|||||||
Reference in New Issue
Block a user