]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
small compression improvement
authorYann Collet <yann.collet.73@gmail.com>
Wed, 4 Nov 2015 12:57:24 +0000 (13:57 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Wed, 4 Nov 2015 12:57:24 +0000 (13:57 +0100)
lib/zstdhc.c
lib/zstdhc_static.h
programs/paramgrill.c

index 716213fd3ad6532d234a7e4414d28f1539880426..e90b7f3a646fd0af9cdd47b314bf9a0c236518e2 100644 (file)
@@ -292,7 +292,7 @@ size_t ZSTD_HC_insertBtAndFindBestMatch (
     const U32 windowLow = windowSize >= current ? 0 : current - windowSize;
     U32* smallerPtr = bt + 2*(current&btMask);
     U32* largerPtr  = bt + 2*(current&btMask) + 1;
-    U32 bestLength = 0;
+    size_t bestLength = 0;
     U32 dummy32;   /* to be nullified at the end */
 
     hashTable[h] = (U32)(ip-base);   /* Update Hash Table */
@@ -307,8 +307,8 @@ size_t ZSTD_HC_insertBtAndFindBestMatch (
 
         if (matchLength > bestLength)
         {
-            bestLength = (U32)matchLength;
-            *offsetPtr = current - matchIndex;
+            if ( (4*(int)(matchLength-bestLength)) > (int)(ZSTD_highbit(current-matchIndex+1) - ZSTD_highbit(offsetPtr[0]+1)) )
+                bestLength = matchLength, *offsetPtr = current - matchIndex;
             if (ip+matchLength == iend)   /* equal : no way to know if inf or sup */
                 break;   /* drop, next to null, to guarantee consistency (is there a way to do better ?) */
         }
index 06174fcdeca7e32cdb734e78e108b0531f387a42..bbe1571347b267ba9a755d08009804b066cfd847 100644 (file)
@@ -116,10 +116,10 @@ static const ZSTD_HC_parameters ZSTD_HC_defaultParameters[ZSTD_HC_MAX_CLEVEL+1]
     { 21, 21, 22,  6,  5, ZSTD_HC_lazydeep },  /* level 14 */
     { 22, 21, 22,  6,  5, ZSTD_HC_lazydeep },  /* level 15 */
     { 22, 21, 22,  5,  5, ZSTD_HC_btlazy2  },  /* level 16 */
-    { 22, 22, 23,  5,  5, ZSTD_HC_btlazy2  },  /* level 17 */
+    { 22, 23, 22,  4,  5, ZSTD_HC_btlazy2  },  /* level 17 */
     { 22, 22, 23,  7,  5, ZSTD_HC_btlazy2  },  /* level 18 */
-    { 24, 24, 22,  7,  5, ZSTD_HC_btlazy2  },  /* level 19 */
-    { 25, 25, 23,  8,  5, ZSTD_HC_btlazy2  },  /* level 20 */
+    { 23, 23, 23,  7,  5, ZSTD_HC_btlazy2  },  /* level 19 */
+    { 24, 25, 23,  8,  5, ZSTD_HC_btlazy2  },  /* level 20 */
     { 25, 25, 23,  8,  5, ZSTD_HC_btlazy2  },  /* level 21 */
     { 25, 25, 23,  8,  5, ZSTD_HC_btlazy2  },  /* level 22 */
     { 25, 25, 23,  8,  5, ZSTD_HC_btlazy2  },  /* level 23 */
index f7cfef98e52cd09ac2ff6edf29623fa6fa6a33d2..40033a6a341cdb1c4a7543833a3fbf7c82b3e63a 100644 (file)
@@ -696,6 +696,7 @@ static void BMK_benchMem(void* srcBuffer, size_t srcSize)
     if (g_singleRun)
     {
         BMK_result_t testResult;
+        ZSTD_HC_validateParams(&g_params, g_blockSize ? g_blockSize : srcSize);
         BMK_benchParam(&testResult, srcBuffer, srcSize, ctx, g_params);
         DISPLAY("\n");
         return;
@@ -978,7 +979,8 @@ int main(int argc, char** argv)
                             argument++;
                             while ((*argument>= '0') && (*argument<='9'))
                             {
-                                if (*argument++) g_params.strategy = ZSTD_HC_lazy;
+                                g_params.strategy = (ZSTD_HC_strategy)((U32)g_params.strategy *10);
+                                g_params.strategy = (ZSTD_HC_strategy)((U32)g_params.strategy + *argument++ - '0');
                             }
                             continue;
                         case 'L':