From 5e00b848a837c82117b6cd6186837e8a7d0bf175 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 30 Nov 2016 16:46:13 -0800 Subject: [PATCH] FSE_compress_wksp() uses less stack space --- lib/common/fse.h | 12 ++++++------ lib/compress/fse_compress.c | 38 ++++++++++++++++++------------------- lib/compress/huf_compress.c | 4 ++-- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/common/fse.h b/lib/common/fse.h index 9de22b5e..0588651e 100644 --- a/lib/common/fse.h +++ b/lib/common/fse.h @@ -302,25 +302,25 @@ unsigned FSE_optimalTableLog_internal(unsigned maxTableLog, size_t srcSize, unsi /* FSE_compress_wksp() : * Same as FSE_compress2(), but using an externally allocated scratch buffer (`workSpace`). - * `workSpace` size must be `(1<2)?(maxTableLog-2):0)) ) +size_t FSE_compress_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize); size_t FSE_buildCTable_raw (FSE_CTable* ct, unsigned nbBits); -/**< build a fake FSE_CTable, designed to not compress an input, where each symbol uses nbBits */ +/**< build a fake FSE_CTable, designed for a flat distribution, where each symbol uses nbBits */ size_t FSE_buildCTable_rle (FSE_CTable* ct, unsigned char symbolValue); /**< build a fake FSE_CTable, designed to compress always the same symbolValue */ /* FSE_buildCTable_wksp() : * Same as FSE_buildCTable(), but using an externally allocated scratch buffer (`workSpace`). - * wkspSize should be sized to handle worst case situation, which is `(1<= `(1<= sizeof(CTable_max_t)); /* A compilation error here means FSE_CTABLE_SIZE_U32 is not large enough */ - if (tableLog > FSE_MAX_TABLELOG) return ERROR(GENERIC); - size = FSE_CTABLE_SIZE_U32 (tableLog, maxSymbolValue) * sizeof(U32); - return size; + if (tableLog > FSE_MAX_TABLELOG) return ERROR(tableLog_tooLarge); + return FSE_CTABLE_SIZE_U32 (tableLog, maxSymbolValue) * sizeof(U32); } FSE_CTable* FSE_createCTable (unsigned maxSymbolValue, unsigned tableLog) @@ -766,9 +756,9 @@ size_t FSE_compressBound(size_t size) { return FSE_COMPRESSBOUND(size); } /* FSE_compress_wksp() : * Same as FSE_compress2(), but using an externally allocated scratch buffer (`workSpace`). - * `workSpace` size must be `(1<= FSE_WKSP_SIZE_U32(FSE_MAX_TABLELOG, FSE_MAX_SYMBOL_VALUE)); /* compilation failures here means scratchBuffer is not large enough */ if (tableLog > FSE_MAX_TABLELOG) return ERROR(tableLog_tooLarge); - return FSE_compress_wksp(dst, dstCapacity, src, srcSize, maxSymbolValue, tableLog, scratchBuffer); + return FSE_compress_wksp(dst, dstCapacity, src, srcSize, maxSymbolValue, tableLog, &scratchBuffer, sizeof(scratchBuffer)); } size_t FSE_compress (void* dst, size_t dstCapacity, const void* src, size_t srcSize) diff --git a/lib/compress/huf_compress.c b/lib/compress/huf_compress.c index d4ae35ec..3a1c0511 100644 --- a/lib/compress/huf_compress.c +++ b/lib/compress/huf_compress.c @@ -92,7 +92,7 @@ size_t HUF_writeCTable (void* dst, size_t maxDstSize, BYTE huffWeight[HUF_SYMBOLVALUE_MAX]; BYTE* op = (BYTE*)dst; #define MAX_FSE_TABLELOG_FOR_HUFF_HEADER 6 - BYTE scratchBuffer[1<1) & (size < maxSymbolValue/2)) { /* FSE compressed */ op[0] = (BYTE)size;