]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
minor CRatio improvement
authorYann Collet <yann.collet.73@gmail.com>
Fri, 6 Nov 2015 17:28:02 +0000 (18:28 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Fri, 6 Nov 2015 17:28:02 +0000 (18:28 +0100)
lib/zstdhc.c
lib/zstdhc_static.h

index e2dfafc1de7fa5f8c56180bec182443d300a4048..dbc7a3a99381bcb6d79b21e48db195554b4ff5fc 100644 (file)
@@ -655,6 +655,7 @@ size_t ZSTD_HC_compressBlock_lazy_generic(ZSTD_HC_CCtx* ctx,
 
         /* let's try to find a better solution */
         start = ip;
+        while ((start>anchor) && (start-offset>ctx->base) && (start[-1] == start[-1-offset])) { start--; matchLength++; }  /* catch up */
 
         while (ip<ilimit)
         {
@@ -670,11 +671,15 @@ size_t ZSTD_HC_compressBlock_lazy_generic(ZSTD_HC_CCtx* ctx,
             {
                 size_t offset2=999999;
                 size_t ml2 = searchMax(ctx, ip, iend, &offset2, maxSearches, mls);
-                int gain2 = (int)(ml2*(3+deep) - ZSTD_highbit((U32)offset2+1));   /* raw approx */
-                int gain1 = (int)(matchLength*(3+deep) - ZSTD_highbit((U32)offset+1) + (3+deep));
+                const BYTE* start2 = ip;
+                int gain1, gain2;
+                if (ml2)
+                    while ((start2>anchor) && (start2-offset2>ctx->base) && (start2[-1] == start2[-1-offset2])) { start2--; ml2++; }  /* catch up */
+                gain2 = (int)(ml2*(3+deep) - ZSTD_highbit((U32)offset2+1));   /* raw approx */
+                gain1 = (int)(matchLength*(3+deep) - ZSTD_highbit((U32)offset+1) + (3+deep));
                 if (gain2 > gain1)
                 {
-                    matchLength = ml2, offset = offset2, start = ip;
+                    matchLength = ml2, offset = offset2, start = start2;
                     continue;   /* search a better one */
                 }
             }
@@ -694,12 +699,16 @@ size_t ZSTD_HC_compressBlock_lazy_generic(ZSTD_HC_CCtx* ctx,
                 {
                     size_t offset2=999999;
                     size_t ml2 = searchMax(ctx, ip, iend, &offset2, maxSearches, mls);
-                    int gain2 = (int)(ml2*4 - ZSTD_highbit((U32)offset2+1));   /* raw approx */
-                    int gain1 = (int)(matchLength*4 - ZSTD_highbit((U32)offset+1) + 7);
+                    const BYTE* start2 = ip;
+                    int gain1, gain2;
+                    if (ml2)
+                        while ((start2>anchor) && (start2-offset2>ctx->base) && (start2[-1] == start2[-1-offset2])) { start2--; ml2++; }  /* catch up */
+                    gain2 = (int)(ml2*(3+deep) - ZSTD_highbit((U32)offset2+1));   /* raw approx */
+                    gain1 = (int)(matchLength*(3+deep) - ZSTD_highbit((U32)offset+1) + (3+deep));
                     if (gain2 > gain1)
                     {
-                        matchLength = ml2, offset = offset2, start = ip;
-                        continue;
+                        matchLength = ml2, offset = offset2, start = start2;
+                        continue;   /* search a better one */
                     }
                 }
             }
@@ -707,8 +716,6 @@ size_t ZSTD_HC_compressBlock_lazy_generic(ZSTD_HC_CCtx* ctx,
         }
 
         /* store sequence */
-        if (offset)
-        while ((start>anchor) && (start-offset>ctx->base) && (start[-1] == start[-1-offset])) { start--; matchLength++; }  /* catch up */
         {
             size_t litLength = start - anchor;
             if (offset) offset_1 = offset;
index 52e9bb88df2641737df97a11f0d9fda665b1c5e5..63214a1b5095e5bde63e29b915805ae187ff2576 100644 (file)
@@ -111,8 +111,8 @@ static const ZSTD_HC_parameters ZSTD_HC_defaultParameters[ZSTD_HC_MAX_CLEVEL+1]
     { 21, 17, 20,  3,  5, ZSTD_HC_lazy    },  /* level  7 */
     { 21, 19, 20,  3,  5, ZSTD_HC_lazy    },  /* level  8 */
     { 21, 19, 20,  4,  5, ZSTD_HC_lazy    },  /* level  9 */
-    { 21, 19, 20,  5,  5, ZSTD_HC_lazy    },  /* level 10 */
-    { 21, 20, 20,  5,  5, ZSTD_HC_lazy    },  /* level 11 */
+    { 21, 19, 20,  4,  5, ZSTD_HC_lazy2   },  /* level 10 */
+    { 21, 20, 21,  4,  5, ZSTD_HC_lazy2   },  /* level 11 */
     { 22, 20, 22,  5,  5, ZSTD_HC_lazy2   },  /* level 12 */
     { 22, 21, 22,  5,  5, ZSTD_HC_lazy2   },  /* level 13 */
     { 22, 22, 23,  5,  5, ZSTD_HC_lazy2   },  /* level 14 */