Modify ZSTD_copyBlockSequences to agree with new API

This commit is contained in:
senhuang42 2020-10-27 10:07:26 -04:00
parent 761f40d1c6
commit 3a11c7eb03
2 changed files with 43 additions and 36 deletions

View File

@ -2442,17 +2442,19 @@ static size_t ZSTD_buildSeqStore(ZSTD_CCtx* zc, const void* src, size_t srcSize)
static void ZSTD_copyBlockSequences(ZSTD_CCtx* zc) static void ZSTD_copyBlockSequences(ZSTD_CCtx* zc)
{ {
const seqStore_t* seqStore = ZSTD_getSeqStore(zc); const seqStore_t* seqStore = ZSTD_getSeqStore(zc);
const seqDef* seqs = seqStore->sequencesStart; const seqDef* seqStoreSeqs = seqStore->sequencesStart;
size_t seqsSize = seqStore->sequences - seqs; size_t seqStoreSeqSize = seqStore->sequences - seqStoreSeqs;
ZSTD_Sequence* outSeqs = &zc->seqCollector.seqStart[zc->seqCollector.seqIndex]; ZSTD_Sequence* outSeqs = &zc->seqCollector.seqStart[zc->seqCollector.seqIndex];
size_t i; size_t position; int repIdx; size_t i;
size_t position;
int repIdx;
assert(zc->seqCollector.seqIndex + 1 < zc->seqCollector.maxSequences); assert(zc->seqCollector.seqIndex + 1 < zc->seqCollector.maxSequences);
for (i = 0, position = 0; i < seqsSize; ++i) { for (i = 0, position = 0; i < seqStoreSeqSize; ++i) {
outSeqs[i].offset = seqs[i].offset; outSeqs[i].offset = seqStoreSeqs[i].offset - ZSTD_REP_NUM;
outSeqs[i].litLength = seqs[i].litLength; outSeqs[i].litLength = seqStoreSeqs[i].litLength;
outSeqs[i].matchLength = seqs[i].matchLength + MINMATCH; outSeqs[i].matchLength = seqStoreSeqs[i].matchLength + MINMATCH;
if (i == seqStore->longLengthPos) { if (i == seqStore->longLengthPos) {
if (seqStore->longLengthID == 1) { if (seqStore->longLengthID == 1) {
@ -2462,32 +2464,36 @@ static void ZSTD_copyBlockSequences(ZSTD_CCtx* zc)
} }
} }
if (outSeqs[i].offset <= ZSTD_REP_NUM) { /* Repcode handling:
outSeqs[i].rep = outSeqs[i].offset; * If litLength != 0:
repIdx = (unsigned int)i - outSeqs[i].offset; * rep == 1 --> offset == repeat offset 1
* rep == 2 --> offset == repeat offset 2
* rep == 3 --> offset == repeat offset 3
* If litLength == 0:
* rep == 1 --> offset == repeat offset 2
* rep == 2 --> offset == repeat offset 3
* rep == 3 --> offset == repeat offset 1 - 1
*/
if (seqStoreSeqs[i].offset <= ZSTD_REP_NUM) {
outSeqs[i].rep = seqStoreSeqs[i].offset;
repIdx = (unsigned int)i - seqStoreSeqs[i].offset;
if (outSeqs[i].litLength == 0) { if (seqStoreSeqs[i].litLength == 0) {
if (outSeqs[i].offset < 3) { if (seqStoreSeqs[i].offset < 3) {
--repIdx; --repIdx;
} else { } else {
repIdx = (unsigned int)i - 1; repIdx = (unsigned int)i - 1;
} }
++outSeqs[i].rep;
} }
assert(repIdx >= -3); assert(repIdx >= -3);
outSeqs[i].offset = repIdx >= 0 ? outSeqs[repIdx].offset : repStartValue[-repIdx - 1]; outSeqs[i].offset = repIdx >= 0 ? outSeqs[repIdx].offset : repStartValue[-repIdx - 1];
if (outSeqs[i].rep == 4) { if (outSeqs[i].rep == 3 && outSeqs[i].litLength == 0) {
--outSeqs[i].offset; --outSeqs[i].offset;
} }
} else {
outSeqs[i].offset -= ZSTD_REP_NUM;
} }
position += outSeqs[i].litLength + outSeqs[i].matchLength;
position += outSeqs[i].litLength;
outSeqs[i].matchPos = (unsigned int)position;
position += outSeqs[i].matchLength;
} }
zc->seqCollector.seqIndex += seqsSize; zc->seqCollector.seqIndex += seqStoreSeqSize;
} }
size_t ZSTD_getSequences(ZSTD_CCtx* zc, ZSTD_Sequence* outSeqs, size_t ZSTD_getSequences(ZSTD_CCtx* zc, ZSTD_Sequence* outSeqs,

View File

@ -1114,24 +1114,25 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
typedef struct ZSTD_CCtx_params_s ZSTD_CCtx_params; typedef struct ZSTD_CCtx_params_s ZSTD_CCtx_params;
typedef struct { typedef struct {
unsigned int offset; /* The offset of the match. unsigned int offset; /* The offset of the match.
* If == 0, then represents a block of literals, determined by litLength * If == 0, then represents a block of literals, determined by litLength
*/ */
unsigned int litLength; /* Literal length */ unsigned int litLength; /* Literal length */
unsigned int matchLength; /* Match length. */ unsigned int matchLength; /* Match length. */
unsigned int rep; /* Represents which repeat offset is used. Ranges from [0, 3].
* If rep == 0, then this sequence does not contain a repeat offset. unsigned int rep; /* Represents which repeat offset is used. Ranges from [0, 3].
* Otherwise: * If rep == 0, then this sequence does not contain a repeat offset.
* If litLength != 0: * Otherwise:
* rep == 1 --> offset == repeat offset 1 * If litLength != 0:
* rep == 2 --> offset == repeat offset 2 * rep == 1 --> offset == repeat offset 1
* rep == 3 --> offset == repeat offset 3 * rep == 2 --> offset == repeat offset 2
* If litLength == 0: * rep == 3 --> offset == repeat offset 3
* rep == 1 --> offset == repeat offset 2 * If litLength == 0:
* rep == 2 --> offset == repeat offset 3 * rep == 1 --> offset == repeat offset 2
* rep == 3 --> offset == repeat offset 1 - 1 * rep == 2 --> offset == repeat offset 3
*/ * rep == 3 --> offset == repeat offset 1 - 1
*/
} ZSTD_Sequence; } ZSTD_Sequence;
typedef struct { typedef struct {