From: senhuang42 Date: Tue, 27 Oct 2020 14:07:26 +0000 (-0400) Subject: Modify ZSTD_copyBlockSequences to agree with new API X-Git-Tag: v1.4.7~39^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a11c7eb035ff949175d99376284b49c8d6ea01a;p=thirdparty%2Fzstd.git Modify ZSTD_copyBlockSequences to agree with new API --- diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index b1bb9fa10..119b90941 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -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) { const seqStore_t* seqStore = ZSTD_getSeqStore(zc); - const seqDef* seqs = seqStore->sequencesStart; - size_t seqsSize = seqStore->sequences - seqs; + const seqDef* seqStoreSeqs = seqStore->sequencesStart; + size_t seqStoreSeqSize = seqStore->sequences - seqStoreSeqs; 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); - for (i = 0, position = 0; i < seqsSize; ++i) { - outSeqs[i].offset = seqs[i].offset; - outSeqs[i].litLength = seqs[i].litLength; - outSeqs[i].matchLength = seqs[i].matchLength + MINMATCH; + for (i = 0, position = 0; i < seqStoreSeqSize; ++i) { + outSeqs[i].offset = seqStoreSeqs[i].offset - ZSTD_REP_NUM; + outSeqs[i].litLength = seqStoreSeqs[i].litLength; + outSeqs[i].matchLength = seqStoreSeqs[i].matchLength + MINMATCH; if (i == seqStore->longLengthPos) { if (seqStore->longLengthID == 1) { @@ -2462,32 +2464,36 @@ static void ZSTD_copyBlockSequences(ZSTD_CCtx* zc) } } - if (outSeqs[i].offset <= ZSTD_REP_NUM) { - outSeqs[i].rep = outSeqs[i].offset; - repIdx = (unsigned int)i - outSeqs[i].offset; - - if (outSeqs[i].litLength == 0) { - if (outSeqs[i].offset < 3) { + /* Repcode handling: + * If litLength != 0: + * 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 (seqStoreSeqs[i].litLength == 0) { + if (seqStoreSeqs[i].offset < 3) { --repIdx; } else { repIdx = (unsigned int)i - 1; } - ++outSeqs[i].rep; } assert(repIdx >= -3); 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; } - } else { - outSeqs[i].offset -= ZSTD_REP_NUM; } - - position += outSeqs[i].litLength; - outSeqs[i].matchPos = (unsigned int)position; - position += outSeqs[i].matchLength; + position += outSeqs[i].litLength + outSeqs[i].matchLength; } - zc->seqCollector.seqIndex += seqsSize; + zc->seqCollector.seqIndex += seqStoreSeqSize; } size_t ZSTD_getSequences(ZSTD_CCtx* zc, ZSTD_Sequence* outSeqs, diff --git a/lib/zstd.h b/lib/zstd.h index c91245663..7668729a1 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -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 { - unsigned int offset; /* The offset of the match. - * If == 0, then represents a block of literals, determined by litLength - */ + unsigned int offset; /* The offset of the match. + * If == 0, then represents a block of literals, determined by litLength + */ unsigned int litLength; /* Literal 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. - * Otherwise: - * If litLength != 0: - * 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 - */ + + 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. + * Otherwise: + * If litLength != 0: + * 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 + */ } ZSTD_Sequence; typedef struct {