]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
ZSTDMT_compressCCtx : fallback to single-thread mode when nbChunks==1
authorYann Collet <cyan@fb.com>
Mon, 23 Jan 2017 08:56:54 +0000 (00:56 -0800)
committerYann Collet <cyan@fb.com>
Mon, 23 Jan 2017 09:20:27 +0000 (01:20 -0800)
lib/compress/zstdmt_compress.c

index 176f940c8811344ca9be7c9956f1de0303874442..18ed7441786940797574ff1e12cab16fd6a2964c 100644 (file)
@@ -360,6 +360,15 @@ size_t ZSTDMT_compressCCtx(ZSTDMT_CCtx* mtctx,
     DEBUGLOG(2, "nbChunks  : %2u   (chunkSize : %u bytes)   ", nbChunks, (U32)avgChunkSize);
     params.fParams.contentSizeFlag = 1;
 
+    if (nbChunks==1) {   /* fallback to single-thread mode */
+        size_t result;
+        ZSTD_CCtx* const cctx = ZSTDMT_getCCtx(mtctx->cctxPool);
+        if (!cctx) return ERROR(memory_allocation);
+        result = ZSTD_compressCCtx(mtctx->cctxPool->cctx[0], dst, dstCapacity, src, srcSize, compressionLevel);
+        ZSTDMT_releaseCCtx(mtctx->cctxPool, cctx);
+        return result;
+    }
+
     {   unsigned u;
         for (u=0; u<nbChunks; u++) {
             size_t const chunkSize = MIN(remainingSrcSize, avgChunkSize);
@@ -433,8 +442,6 @@ size_t ZSTDMT_compressCCtx(ZSTDMT_CCtx* mtctx,
 /* =======      Streaming API     ======= */
 /* ====================================== */
 
-#if 1
-
 static void ZSTDMT_waitForAllJobsCompleted(ZSTDMT_CCtx* zcs) {
     while (zcs->doneJobID < zcs->nextJobID) {
         unsigned const jobID = zcs->doneJobID & zcs->jobIDMask;
@@ -708,6 +715,3 @@ size_t ZSTDMT_endStream(ZSTDMT_CCtx* zcs, ZSTD_outBuffer* output)
 {
     return ZSTDMT_flushStream_internal(zcs, output, 1);
 }
-
-
-#endif