MCPcopy Create free account
hub / github.com/F-Stack/f-stack / FIO_createCResources

Function FIO_createCResources

freebsd/contrib/zstd/programs/fileio.c:926–1008  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

924}
925
926static cRess_t FIO_createCResources(FIO_prefs_t* const prefs,
927 const char* dictFileName, unsigned long long const maxSrcFileSize,
928 int cLevel, ZSTD_compressionParameters comprParams) {
929 cRess_t ress;
930 memset(&ress, 0, sizeof(ress));
931
932 DISPLAYLEVEL(6, "FIO_createCResources \n");
933 ress.cctx = ZSTD_createCCtx();
934 if (ress.cctx == NULL)
935 EXM_THROW(30, "allocation error (%s): can't create ZSTD_CCtx",
936 strerror(errno));
937 ress.srcBufferSize = ZSTD_CStreamInSize();
938 ress.srcBuffer = malloc(ress.srcBufferSize);
939 ress.dstBufferSize = ZSTD_CStreamOutSize();
940
941 /* need to update memLimit before calling createDictBuffer
942 * because of memLimit check inside it */
943 if (prefs->patchFromMode) {
944 unsigned long long const ssSize = (unsigned long long)prefs->streamSrcSize;
945 FIO_adjustParamsForPatchFromMode(prefs, &comprParams, UTIL_getFileSize(dictFileName), ssSize > 0 ? ssSize : maxSrcFileSize, cLevel);
946 }
947 ress.dstBuffer = malloc(ress.dstBufferSize);
948 ress.dictBufferSize = FIO_createDictBuffer(&ress.dictBuffer, dictFileName, prefs); /* works with dictFileName==NULL */
949 if (!ress.srcBuffer || !ress.dstBuffer)
950 EXM_THROW(31, "allocation error : not enough memory");
951
952 /* Advanced parameters, including dictionary */
953 if (dictFileName && (ress.dictBuffer==NULL))
954 EXM_THROW(32, "allocation error : can't create dictBuffer");
955 ress.dictFileName = dictFileName;
956
957 if (prefs->adaptiveMode && !prefs->ldmFlag && !comprParams.windowLog)
958 comprParams.windowLog = ADAPT_WINDOWLOG_DEFAULT;
959
960 CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_contentSizeFlag, prefs->contentSize) ); /* always enable content size when available (note: supposed to be default) */
961 CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_dictIDFlag, prefs->dictIDFlag) );
962 CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_checksumFlag, prefs->checksumFlag) );
963 /* compression level */
964 CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_compressionLevel, cLevel) );
965 /* max compressed block size */
966 CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_targetCBlockSize, (int)prefs->targetCBlockSize) );
967 /* source size hint */
968 CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_srcSizeHint, (int)prefs->srcSizeHint) );
969 /* long distance matching */
970 CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_enableLongDistanceMatching, prefs->ldmFlag) );
971 CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_ldmHashLog, prefs->ldmHashLog) );
972 CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_ldmMinMatch, prefs->ldmMinMatch) );
973 if (prefs->ldmBucketSizeLog != FIO_LDM_PARAM_NOTSET) {
974 CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_ldmBucketSizeLog, prefs->ldmBucketSizeLog) );
975 }
976 if (prefs->ldmHashRateLog != FIO_LDM_PARAM_NOTSET) {
977 CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_ldmHashRateLog, prefs->ldmHashRateLog) );
978 }
979 /* compression parameters */
980 CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_windowLog, (int)comprParams.windowLog) );
981 CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_chainLog, (int)comprParams.chainLog) );
982 CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_hashLog, (int)comprParams.hashLog) );
983 CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_searchLog, (int)comprParams.searchLog) );

Callers 2

FIO_compressFilenameFunction · 0.85

Calls 11

memsetFunction · 0.85
mallocFunction · 0.85
UTIL_getFileSizeFunction · 0.85
FIO_createDictBufferFunction · 0.85
ZSTD_createCCtxFunction · 0.50
ZSTD_CStreamInSizeFunction · 0.50
ZSTD_CStreamOutSizeFunction · 0.50
ZSTD_CCtx_setParameterFunction · 0.50
ZSTD_CCtx_refPrefixFunction · 0.50
ZSTD_CCtx_loadDictionaryFunction · 0.50

Tested by

no test coverage detected