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) {
}
}
- 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,
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 {