From 987cb4ca6a526923918d40ad65d21e5ef3c724c3 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Mon, 12 Oct 2020 14:09:12 -0700 Subject: [PATCH] [lib] Take the shortcut when ZSTD_c_stableOutBuffer is set 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index a7ab4dea3..acd150b9d 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -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,