]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
minor refactor
authorYann Collet <yann.collet.73@gmail.com>
Sat, 19 Mar 2016 14:11:42 +0000 (15:11 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Sat, 19 Mar 2016 14:11:42 +0000 (15:11 +0100)
lib/zstd_compress.c
lib/zstd_decompress.c
lib/zstd_internal.h

index ebe4cdc9219d7d894b958fa9921b5c4cd5e02de3..e7c249bfe64103ca51bee673adda09c23256c90c 100644 (file)
@@ -948,7 +948,6 @@ static size_t ZSTD_hashPtr(const void* p, U32 hBits, U32 mls)
 /*-*************************************
 *  Fast Scan
 ***************************************/
-#define FILLHASHSTEP 3
 static void ZSTD_fillHashTable (ZSTD_CCtx* zc, const void* end, const U32 mls)
 {
     U32* const hashTable = zc->hashTable;
@@ -956,10 +955,11 @@ static void ZSTD_fillHashTable (ZSTD_CCtx* zc, const void* end, const U32 mls)
     const BYTE* const base = zc->base;
     const BYTE* ip = base + zc->nextToUpdate;
     const BYTE* const iend = ((const BYTE*)end) - 8;
+    const size_t fastHashFillStep = 3;
 
     while(ip <= iend) {
         hashTable[ZSTD_hashPtr(ip, hBits, mls)] = (U32)(ip - base);
-        ip += FILLHASHSTEP;
+        ip += fastHashFillStep;
     }
 }
 
@@ -980,10 +980,8 @@ void ZSTD_compressBlock_fast_generic(ZSTD_CCtx* zc,
     const BYTE* const lowest = base + lowIndex;
     const BYTE* const iend = istart + srcSize;
     const BYTE* const ilimit = iend - 8;
-
     size_t offset_2=REPCODE_STARTVALUE, offset_1=REPCODE_STARTVALUE;
 
-
     /* init */
     ZSTD_resetSeqStore(seqStorePtr);
     if (ip < lowest+REPCODE_STARTVALUE) ip = lowest+REPCODE_STARTVALUE;
@@ -2196,9 +2194,7 @@ size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* zc,
 
     /* Write Frame Header into ctx headerBuffer */
     MEM_writeLE32(zc->headerBuffer, ZSTD_MAGICNUMBER);
-    {
-        BYTE* const op = (BYTE*)zc->headerBuffer;
-        U32 const fcsSize[4] = { 0, 1, 2, 8 };
+    {   BYTE* const op = (BYTE*)zc->headerBuffer;
         U32 const fcsId = (params.srcSize>0) + (params.srcSize>=256) + (params.srcSize>=65536+256);   /* 0-3 */
         BYTE fdescriptor = (BYTE)(params.windowLog - ZSTD_WINDOWLOG_ABSOLUTEMIN);   /* windowLog : 4 KB - 128 MB */
         fdescriptor |= (BYTE)((params.searchLength==3)<<4);   /* mml : 3-4 */
@@ -2212,7 +2208,7 @@ size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* zc,
             case 2 : MEM_writeLE16(op+5, (U16)(params.srcSize-256)); break;
             case 3 : MEM_writeLE64(op+5, (U64)(params.srcSize)); break;
         }
-        zc->hbSize = ZSTD_frameHeaderSize_min + fcsSize[fcsId];
+        zc->hbSize = ZSTD_frameHeaderSize_min + ZSTD_fcs_fieldSize[fcsId];
     }
 
     zc->stage = 0;
index 6b9b12972b369570c74c0c0d923fffd8a5e63371..ecc4329bdc0fcdf4877adfa4eb9379dd3ddef1fc 100644 (file)
@@ -75,7 +75,6 @@
 #  pragma warning(disable : 4127)        /* disable: C4127: conditional expression is constant */
 #  pragma warning(disable : 4324)        /* disable: C4324: padded structure */
 #else
-#  define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
 #  ifdef __GNUC__
 #    define FORCE_INLINE static inline __attribute__((always_inline))
 #  else
@@ -276,8 +275,6 @@ void ZSTD_copyDCtx(ZSTD_DCtx* dstDCtx, const ZSTD_DCtx* srcDCtx)
       TO DO
 */
 
-static const size_t ZSTD_fcs_fieldSize[4] = { 0, 1, 2, 8 };
-
 /** ZSTD_frameHeaderSize() :
 *   srcSize must be >= ZSTD_frameHeaderSize_min.
 *   @return : size of the Frame Header */
index c5cc64cd5f9a98fc7340829f586279ba4f852120..ba350c4f69e1bb2d67d86d423714f0b6182018a1 100644 (file)
@@ -71,9 +71,6 @@
 #define MB *(1 <<20)
 #define GB *(1U<<30)
 
-#define ZSTD_BLOCKHEADERSIZE 3   /* because C standard does not allow a static const value to be defined using another static const value .... :( */
-static const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
-
 #define BIT7 128
 #define BIT6  64
 #define BIT5  32
@@ -81,16 +78,28 @@ static const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
 #define BIT1   2
 #define BIT0   1
 
+#define ZSTD_WINDOWLOG_ABSOLUTEMIN 12
+static const size_t ZSTD_fcs_fieldSize[4] = { 0, 1, 2, 8 };
+
+#define ZSTD_BLOCKHEADERSIZE 3   /* because C standard does not allow a static const value to be defined using another static const value .... :( */
+static const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
+typedef enum { bt_compressed, bt_raw, bt_rle, bt_end } blockType_t;
+
+#define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
+#define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */)   /* for a non-null block */
+
+#define HufLog 12
+
 #define IS_HUF 0
 #define IS_PCH 1
 #define IS_RAW 2
 #define IS_RLE 3
 
+#define LONGNBSEQ 0x7F00
+
 #define MINMATCH 4
 #define REPCODE_STARTVALUE 1
-#define ZSTD_WINDOWLOG_ABSOLUTEMIN 12
-
-#define LONGNBSEQ 0x7F00
+#define HASHLOG3 17
 
 #define Litbits  8
 #define MLbits   7
@@ -110,26 +119,16 @@ static const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
 #define FSE_ENCODING_STATIC  2
 #define FSE_ENCODING_DYNAMIC 3
 
-#define HufLog 12
-#define HASHLOG3 17
-
-#define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
-#define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */)   /* for a non-null block */
-
-#define WILDCOPY_OVERLENGTH 8
-
-typedef enum { bt_compressed, bt_raw, bt_rle, bt_end } blockType_t;
-
 
 /*-*******************************************
 *  Shared functions to include for inlining
 *********************************************/
 static void ZSTD_copy8(void* dst, const void* src) { memcpy(dst, src, 8); }
-
 #define COPY8(d,s) { ZSTD_copy8(d,s); d+=8; s+=8; }
 
 /*! ZSTD_wildcopy() :
 *   custom version of memcpy(), can copy up to 7 bytes too many (8 bytes if length==0) */
+#define WILDCOPY_OVERLENGTH 8
 MEM_STATIC void ZSTD_wildcopy(void* dst, const void* src, size_t length)
 {
     const BYTE* ip = (const BYTE*)src;