]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[lib] Take the shortcut when ZSTD_c_stableOutBuffer is set
authorNick Terrell <terrelln@fb.com>
Mon, 12 Oct 2020 21:09:12 +0000 (14:09 -0700)
committerNick Terrell <terrelln@fb.com>
Fri, 30 Oct 2020 17:55:34 +0000 (10:55 -0700)
When we have a stable output buffer take the single-pass shortcut.
It is okay to return `dstSizeTooSmall` if the output buffer isn't
big enough, because we know it will never grow.

lib/compress/zstd_compress.c

index a7ab4dea3dd43280199e0dfc2a04d7722cdb3552..acd150b9d1b1ab1a4964e4b57d534bdc1a0768b2 100644 (file)
@@ -4064,7 +4064,8 @@ static size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
 
         case zcss_load:
             if ( (flushMode == ZSTD_e_end)
-              && ((size_t)(oend-op) >= ZSTD_compressBound(iend-ip))  /* enough dstCapacity */
+              && ( (size_t)(oend-op) >= ZSTD_compressBound(iend-ip)     /* Enough output space */
+                || zcs->appliedParams.outBufferMode == ZSTD_bm_stable)  /* OR we are allowed to return dstSizeTooSmall */
               && (zcs->inBuffPos == 0) ) {
                 /* shortcut to compression pass directly into output buffer */
                 size_t const cSize = ZSTD_compressEnd(zcs,