Pull compressStream2() transparent initialization into its own function
This commit is contained in:
@@ -4334,20 +4334,9 @@ static size_t ZSTD_checkBufferStability(ZSTD_CCtx const* cctx,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
|
static size_t ZSTD_CCtx_init_compressStream2(ZSTD_CCtx* cctx,
|
||||||
ZSTD_outBuffer* output,
|
ZSTD_EndDirective endOp,
|
||||||
ZSTD_inBuffer* input,
|
size_t inSize) {
|
||||||
ZSTD_EndDirective endOp)
|
|
||||||
{
|
|
||||||
DEBUGLOG(5, "ZSTD_compressStream2, endOp=%u ", (unsigned)endOp);
|
|
||||||
/* check conditions */
|
|
||||||
RETURN_ERROR_IF(output->pos > output->size, dstSize_tooSmall, "invalid output buffer");
|
|
||||||
RETURN_ERROR_IF(input->pos > input->size, srcSize_wrong, "invalid input buffer");
|
|
||||||
RETURN_ERROR_IF((U32)endOp > (U32)ZSTD_e_end, parameter_outOfBound, "invalid endDirective");
|
|
||||||
assert(cctx != NULL);
|
|
||||||
|
|
||||||
/* transparent initialization stage */
|
|
||||||
if (cctx->streamStage == zcss_init) {
|
|
||||||
ZSTD_CCtx_params params = cctx->requestedParams;
|
ZSTD_CCtx_params params = cctx->requestedParams;
|
||||||
ZSTD_prefixDict const prefixDict = cctx->prefixDict;
|
ZSTD_prefixDict const prefixDict = cctx->prefixDict;
|
||||||
FORWARD_IF_ERROR( ZSTD_initLocalDict(cctx) , ""); /* Init the local dict if present. */
|
FORWARD_IF_ERROR( ZSTD_initLocalDict(cctx) , ""); /* Init the local dict if present. */
|
||||||
@@ -4356,7 +4345,7 @@ size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
|
|||||||
if (cctx->cdict)
|
if (cctx->cdict)
|
||||||
params.compressionLevel = cctx->cdict->compressionLevel; /* let cdict take priority in terms of compression level */
|
params.compressionLevel = cctx->cdict->compressionLevel; /* let cdict take priority in terms of compression level */
|
||||||
DEBUGLOG(4, "ZSTD_compressStream2 : transparent init stage");
|
DEBUGLOG(4, "ZSTD_compressStream2 : transparent init stage");
|
||||||
if (endOp == ZSTD_e_end) cctx->pledgedSrcSizePlusOne = input->size + 1; /* auto-fix pledgedSrcSize */
|
if (endOp == ZSTD_e_end) cctx->pledgedSrcSizePlusOne = inSize + 1; /* auto-fix pledgedSrcSize */
|
||||||
{
|
{
|
||||||
size_t const dictSize = prefixDict.dict
|
size_t const dictSize = prefixDict.dict
|
||||||
? prefixDict.dictSize
|
? prefixDict.dictSize
|
||||||
@@ -4417,8 +4406,25 @@ size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
|
|||||||
cctx->streamStage = zcss_load;
|
cctx->streamStage = zcss_load;
|
||||||
cctx->frameEnded = 0;
|
cctx->frameEnded = 0;
|
||||||
}
|
}
|
||||||
/* Set initial buffer expectations now that we've initialized */
|
return 0;
|
||||||
ZSTD_setBufferExpectations(cctx, output, input);
|
}
|
||||||
|
|
||||||
|
size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
|
||||||
|
ZSTD_outBuffer* output,
|
||||||
|
ZSTD_inBuffer* input,
|
||||||
|
ZSTD_EndDirective endOp)
|
||||||
|
{
|
||||||
|
DEBUGLOG(5, "ZSTD_compressStream2, endOp=%u ", (unsigned)endOp);
|
||||||
|
/* check conditions */
|
||||||
|
RETURN_ERROR_IF(output->pos > output->size, dstSize_tooSmall, "invalid output buffer");
|
||||||
|
RETURN_ERROR_IF(input->pos > input->size, srcSize_wrong, "invalid input buffer");
|
||||||
|
RETURN_ERROR_IF((U32)endOp > (U32)ZSTD_e_end, parameter_outOfBound, "invalid endDirective");
|
||||||
|
assert(cctx != NULL);
|
||||||
|
|
||||||
|
/* transparent initialization stage */
|
||||||
|
if (cctx->streamStage == zcss_init) {
|
||||||
|
ZSTD_CCtx_init_compressStream2(cctx, endOp, input->size);
|
||||||
|
ZSTD_setBufferExpectations(cctx, output, input); /* Set initial buffer expectations now that we've initialized */
|
||||||
}
|
}
|
||||||
/* end of transparent initialization stage */
|
/* end of transparent initialization stage */
|
||||||
|
|
||||||
@@ -4771,42 +4777,16 @@ size_t ZSTD_compressSequences_ext(void* dst, size_t dstCapacity,
|
|||||||
size_t compressedBlocksSize = 0;
|
size_t compressedBlocksSize = 0;
|
||||||
size_t frameHeaderSize = 0;
|
size_t frameHeaderSize = 0;
|
||||||
|
|
||||||
|
/* Transparent initialization stage, same as compressStream2() */
|
||||||
DEBUGLOG(4, "ZSTD_compressSequences_ext()");
|
DEBUGLOG(4, "ZSTD_compressSequences_ext()");
|
||||||
ZSTD_CCtx_reset(cctx, ZSTD_reset_session_and_parameters);
|
ZSTD_CCtx_reset(cctx, ZSTD_reset_session_and_parameters);
|
||||||
ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, 1);
|
ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, 1);
|
||||||
/* Initialization stage */
|
ZSTD_CCtx_init_compressStream2(cctx, ZSTD_e_end, srcSize);
|
||||||
{
|
|
||||||
ZSTD_CCtx_params params = cctx->requestedParams;
|
|
||||||
ZSTD_prefixDict const prefixDict = cctx->prefixDict;
|
|
||||||
FORWARD_IF_ERROR( ZSTD_initLocalDict(cctx) , ""); /* Init the local dict if present. */
|
|
||||||
ZSTD_memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict)); /* single usage */
|
|
||||||
assert(prefixDict.dict==NULL || cctx->cdict==NULL); /* only one can be set */
|
|
||||||
if (cctx->cdict)
|
|
||||||
params.compressionLevel = cctx->cdict->compressionLevel; /* let cdict take priority in terms of compression level */
|
|
||||||
cctx->pledgedSrcSizePlusOne = srcSize + 1; /* auto-fix pledgedSrcSize */
|
|
||||||
|
|
||||||
size_t const dictSize = prefixDict.dict
|
|
||||||
? prefixDict.dictSize
|
|
||||||
: (cctx->cdict ? cctx->cdict->dictContentSize : 0);
|
|
||||||
ZSTD_cParamMode_e const mode = ZSTD_getCParamMode(cctx->cdict, ¶ms, cctx->pledgedSrcSizePlusOne - 1);
|
|
||||||
params.cParams = ZSTD_getCParamsFromCCtxParams(
|
|
||||||
¶ms, cctx->pledgedSrcSizePlusOne-1,
|
|
||||||
dictSize, mode);
|
|
||||||
|
|
||||||
U64 const pledgedSrcSize = cctx->pledgedSrcSizePlusOne - 1;
|
|
||||||
cctx->blockSize = srcSize;
|
|
||||||
assert(!ZSTD_isError(ZSTD_checkCParams(params.cParams)));
|
|
||||||
FORWARD_IF_ERROR( ZSTD_compressBegin_internal(cctx,
|
|
||||||
prefixDict.dict, prefixDict.dictSize, prefixDict.dictContentType, ZSTD_dtlm_fast,
|
|
||||||
cctx->cdict,
|
|
||||||
¶ms, pledgedSrcSize,
|
|
||||||
ZSTDb_buffered) , "");
|
|
||||||
assert(cctx->appliedParams.nbWorkers == 0);
|
|
||||||
}
|
|
||||||
DEBUGLOG(4, "CCtx blockSize: %zu", cctx->blockSize);
|
DEBUGLOG(4, "CCtx blockSize: %zu", cctx->blockSize);
|
||||||
if (dstCapacity < ZSTD_compressBound(srcSize))
|
if (dstCapacity < ZSTD_compressBound(srcSize))
|
||||||
RETURN_ERROR(dstSize_tooSmall, "Destination buffer too small!");
|
RETURN_ERROR(dstSize_tooSmall, "Destination buffer too small!");
|
||||||
|
|
||||||
|
/* Begin writing output */
|
||||||
frameHeaderSize = ZSTD_writeFrameHeader(op, dstCapacity, &cctx->appliedParams, srcSize, cctx->dictID);
|
frameHeaderSize = ZSTD_writeFrameHeader(op, dstCapacity, &cctx->appliedParams, srcSize, cctx->dictID);
|
||||||
op += frameHeaderSize;
|
op += frameHeaderSize;
|
||||||
dstCapacity -= frameHeaderSize;
|
dstCapacity -= frameHeaderSize;
|
||||||
|
|||||||
Reference in New Issue
Block a user