From 9dd12742f3992dc2f97f0a544e218633253fc82c Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 10 Jun 2016 00:12:26 +0200 Subject: [PATCH] `litBlockType_t` is an `enum` --- lib/common/zstd_internal.h | 5 +---- lib/compress/zstd_compress.c | 16 ++++++++-------- lib/decompress/zstd_decompress.c | 17 +++++++++-------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/common/zstd_internal.h b/lib/common/zstd_internal.h index ebf3e880..6dea0f51 100644 --- a/lib/common/zstd_internal.h +++ b/lib/common/zstd_internal.h @@ -94,10 +94,7 @@ typedef enum { bt_compressed, bt_raw, bt_rle, bt_end } blockType_t; #define HufLog 12 -#define IS_HUF 0 -#define IS_PCH 1 -#define IS_RAW 2 -#define IS_RLE 3 +typedef enum { lbt_huffman, lbt_repeat, lbt_raw, lbt_rle } litBlockType_t; #define LONGNBSEQ 0x7F00 diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 9a94cd97..ad848a7d 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -575,15 +575,15 @@ static size_t ZSTD_noCompressLiterals (void* dst, size_t dstCapacity, const void switch(flSize) { case 1: /* 2 - 1 - 5 */ - ostart[0] = (BYTE)((IS_RAW<<6) + (0<<5) + srcSize); + ostart[0] = (BYTE)((lbt_raw<<6) + (0<<5) + srcSize); break; case 2: /* 2 - 2 - 12 */ - ostart[0] = (BYTE)((IS_RAW<<6) + (2<<4) + (srcSize >> 8)); + ostart[0] = (BYTE)((lbt_raw<<6) + (2<<4) + (srcSize >> 8)); ostart[1] = (BYTE)srcSize; break; default: /*note : should not be necessary : flSize is within {1,2,3} */ case 3: /* 2 - 2 - 20 */ - ostart[0] = (BYTE)((IS_RAW<<6) + (3<<4) + (srcSize >> 16)); + ostart[0] = (BYTE)((lbt_raw<<6) + (3<<4) + (srcSize >> 16)); ostart[1] = (BYTE)(srcSize>>8); ostart[2] = (BYTE)srcSize; break; @@ -603,15 +603,15 @@ static size_t ZSTD_compressRleLiteralsBlock (void* dst, size_t dstCapacity, cons switch(flSize) { case 1: /* 2 - 1 - 5 */ - ostart[0] = (BYTE)((IS_RLE<<6) + (0<<5) + srcSize); + ostart[0] = (BYTE)((lbt_rle<<6) + (0<<5) + srcSize); break; case 2: /* 2 - 2 - 12 */ - ostart[0] = (BYTE)((IS_RLE<<6) + (2<<4) + (srcSize >> 8)); + ostart[0] = (BYTE)((lbt_rle<<6) + (2<<4) + (srcSize >> 8)); ostart[1] = (BYTE)srcSize; break; default: /*note : should not be necessary : flSize is necessarily within {1,2,3} */ case 3: /* 2 - 2 - 20 */ - ostart[0] = (BYTE)((IS_RLE<<6) + (3<<4) + (srcSize >> 16)); + ostart[0] = (BYTE)((lbt_rle<<6) + (3<<4) + (srcSize >> 16)); ostart[1] = (BYTE)(srcSize>>8); ostart[2] = (BYTE)srcSize; break; @@ -632,7 +632,7 @@ static size_t ZSTD_compressLiterals (ZSTD_CCtx* zc, size_t const lhSize = 3 + (srcSize >= 1 KB) + (srcSize >= 16 KB); BYTE* const ostart = (BYTE*)dst; U32 singleStream = srcSize < 256; - U32 hType = IS_HUF; + litBlockType_t hType = lbt_huffman; size_t cLitSize; @@ -644,7 +644,7 @@ static size_t ZSTD_compressLiterals (ZSTD_CCtx* zc, if (dstCapacity < lhSize+1) return ERROR(dstSize_tooSmall); /* not enough space for compression */ if (zc->flagStaticTables && (lhSize==3)) { - hType = IS_PCH; + hType = lbt_repeat; singleStream = 1; cLitSize = HUF_compress1X_usingCTable(ostart+lhSize, dstCapacity-lhSize, src, srcSize, zc->hufTable); } else { diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index 9a41228c..714dbee7 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -450,13 +450,14 @@ size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx, const void* src, size_t srcSize) /* note : srcSize < BLOCKSIZE */ { const BYTE* const istart = (const BYTE*) src; + litBlockType_t lbt; - /* any compressed block with literals segment must be at least this size */ if (srcSize < MIN_CBLOCK_SIZE) return ERROR(corruption_detected); + lbt = (litBlockType_t)(istart[0]>> 6); - switch(istart[0]>> 6) + switch(lbt) { - case IS_HUF: + case lbt_huffman: { size_t litSize, litCSize, singleStream=0; U32 lhSize = ((istart[0]) >> 4) & 3; if (srcSize < 5) return ERROR(corruption_detected); /* srcSize >= MIN_CBLOCK_SIZE == 3; here we need up to 5 for lhSize, + cSize (+nbSeq) */ @@ -495,7 +496,7 @@ size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx, dctx->litSize = litSize; return litCSize + lhSize; } - case IS_PCH: + case lbt_repeat: { size_t litSize, litCSize; U32 lhSize = ((istart[0]) >> 4) & 3; if (lhSize != 1) /* only case supported for now : small litSize, single stream */ @@ -516,7 +517,7 @@ size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx, dctx->litSize = litSize; return litCSize + lhSize; } - case IS_RAW: + case lbt_raw: { size_t litSize; U32 lhSize = ((istart[0]) >> 4) & 3; switch(lhSize) @@ -547,7 +548,7 @@ size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx, dctx->litSize = litSize; return lhSize+litSize; } - case IS_RLE: + case lbt_rle: { size_t litSize; U32 lhSize = ((istart[0]) >> 4) & 3; switch(lhSize) @@ -1317,7 +1318,7 @@ ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictSize, ZSTD_cu /*! ZSTD_createDDict() : * Create a digested dictionary, ready to start decompression operation without startup delay. -* `dict` can be released after creation */ +* `dict` can be released after `ZSTD_DDict` creation */ ZSTD_DDict* ZSTD_createDDict(const void* dict, size_t dictSize) { ZSTD_customMem const allocator = { NULL, NULL, NULL }; @@ -1336,7 +1337,7 @@ size_t ZSTD_freeDDict(ZSTD_DDict* ddict) /*! ZSTD_decompress_usingDDict() : * Decompression using a pre-digested Dictionary -* In contrast with older ZSTD_decompress_usingDict(), use dictionary without significant overhead. */ +* Use dictionary without significant overhead. */ ZSTDLIB_API size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize,