Reduce number of memcpy() calls
This commit is contained in:
@@ -2498,11 +2498,11 @@ static void ZSTD_copyBlockSequences(ZSTD_CCtx* zc)
|
|||||||
ZSTD_Sequence* outSeqs = &zc->seqCollector.seqStart[zc->seqCollector.seqIndex];
|
ZSTD_Sequence* outSeqs = &zc->seqCollector.seqStart[zc->seqCollector.seqIndex];
|
||||||
size_t i;
|
size_t i;
|
||||||
repcodes_t updatedRepcodes;
|
repcodes_t updatedRepcodes;
|
||||||
U32* rep = zc->blockState.prevCBlock->rep;
|
|
||||||
|
|
||||||
assert(zc->seqCollector.seqIndex + 1 < zc->seqCollector.maxSequences);
|
assert(zc->seqCollector.seqIndex + 1 < zc->seqCollector.maxSequences);
|
||||||
/* Ensure we have enough space for last literals "sequence" */
|
/* Ensure we have enough space for last literals "sequence" */
|
||||||
assert(zc->seqCollector.maxSequences >= seqStoreSeqSize + 1);
|
assert(zc->seqCollector.maxSequences >= seqStoreSeqSize + 1);
|
||||||
|
ZSTD_memcpy(updatedRepcodes.rep, zc->blockState.prevCBlock->rep, sizeof(repcodes_t));
|
||||||
for (i = 0; i < seqStoreSeqSize; ++i) {
|
for (i = 0; i < seqStoreSeqSize; ++i) {
|
||||||
U32 rawOffset = seqStoreSeqs[i].offset - ZSTD_REP_NUM;
|
U32 rawOffset = seqStoreSeqs[i].offset - ZSTD_REP_NUM;
|
||||||
outSeqs[i].litLength = seqStoreSeqs[i].litLength;
|
outSeqs[i].litLength = seqStoreSeqs[i].litLength;
|
||||||
@@ -2521,22 +2521,23 @@ static void ZSTD_copyBlockSequences(ZSTD_CCtx* zc)
|
|||||||
/* Derive the correct offset corresponding to a repcode */
|
/* Derive the correct offset corresponding to a repcode */
|
||||||
outSeqs[i].rep = seqStoreSeqs[i].offset;
|
outSeqs[i].rep = seqStoreSeqs[i].offset;
|
||||||
if (outSeqs[i].litLength != 0) {
|
if (outSeqs[i].litLength != 0) {
|
||||||
rawOffset = rep[outSeqs[i].rep - 1];
|
rawOffset = updatedRepcodes.rep[outSeqs[i].rep - 1];
|
||||||
} else {
|
} else {
|
||||||
if (outSeqs[i].rep == 3) {
|
if (outSeqs[i].rep == 3) {
|
||||||
rawOffset = rep[0] - 1;
|
rawOffset = updatedRepcodes.rep[0] - 1;
|
||||||
} else {
|
} else {
|
||||||
rawOffset = rep[outSeqs[i].rep];
|
rawOffset = updatedRepcodes.rep[outSeqs[i].rep];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outSeqs[i].offset = rawOffset;
|
outSeqs[i].offset = rawOffset;
|
||||||
updatedRepcodes = ZSTD_updateRep(rep, seqStoreSeqs[i].offset - 1, seqStoreSeqs[i].litLength == 0);
|
/* seqStoreSeqs[i].offset == offCode+1, and ZSTD_updateRep() expects offCode
|
||||||
ZSTD_memcpy(rep, updatedRepcodes.rep, sizeof(repcodes_t));
|
so we provide seqStoreSeqs[i].offset - 1 */
|
||||||
|
updatedRepcodes = ZSTD_updateRep(updatedRepcodes.rep,
|
||||||
|
seqStoreSeqs[i].offset - 1,
|
||||||
|
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.
|
||||||
* If there are no last literals, then we'll emit (of: 0, ml: 0, ll: 0), which is a marker
|
* If there are no last literals, then we'll emit (of: 0, ml: 0, ll: 0), which is a marker
|
||||||
* for the block boundary, according to the API.
|
* for the block boundary, according to the API.
|
||||||
@@ -2546,9 +2547,6 @@ static void ZSTD_copyBlockSequences(ZSTD_CCtx* zc)
|
|||||||
outSeqs[i].litLength = (U32)lastLLSize;
|
outSeqs[i].litLength = (U32)lastLLSize;
|
||||||
outSeqs[i].matchLength = outSeqs[i].offset = outSeqs[i].rep = 0;
|
outSeqs[i].matchLength = outSeqs[i].offset = outSeqs[i].rep = 0;
|
||||||
seqStoreSeqSize++;
|
seqStoreSeqSize++;
|
||||||
|
|
||||||
ZSTD_memcpy(zc->blockState.nextCBlock->rep, zc->blockState.prevCBlock->rep,
|
|
||||||
sizeof(zc->blockState.nextCBlock->rep));
|
|
||||||
zc->seqCollector.seqIndex += seqStoreSeqSize;
|
zc->seqCollector.seqIndex += seqStoreSeqSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2721,7 +2721,7 @@ static int basicUnitTests(U32 const seed, double compressibility)
|
|||||||
|
|
||||||
if (seqs == NULL) goto _output_error;
|
if (seqs == NULL) goto _output_error;
|
||||||
assert(cctx != NULL);
|
assert(cctx != NULL);
|
||||||
|
ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, 19);
|
||||||
/* Populate src with random data */
|
/* Populate src with random data */
|
||||||
RDG_genBuffer(CNBuffer, srcSize, compressibility, 0.5, seed);
|
RDG_genBuffer(CNBuffer, srcSize, compressibility, 0.5, seed);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user