added code comments
authorYann Collet <cyan@fb.com>
Thu, 9 Nov 2017 01:56:20 +0000 (17:56 -0800)
committerYann Collet <cyan@fb.com>
Thu, 9 Nov 2017 01:56:20 +0000 (17:56 -0800)
lib/lz4opt.h

index 7f74df9..9917851 100644 (file)
@@ -184,8 +184,13 @@ static int LZ4HC_compress_optimal (
             DEBUGLOG(7, "rPos:%u[%u] vs [%u]%u",
                     cur, opt[cur].price, opt[cur+1].price, cur+1);
             if (fullUpdate) {
-                if ((opt[cur+1].price <= opt[cur].price) && (opt[cur+MINMATCH].price < opt[cur].price + 3/*min seq price*/)) continue;
+                /* not useful to search here if next position has same (or lower) cost */
+                if ( (opt[cur+1].price <= opt[cur].price)
+                  /* in some cases, next position has same cost, but cost rises sharply after, so a small match would still be beneficial */
+                  && (opt[cur+MINMATCH].price < opt[cur].price + 3/*min seq price*/) )
+                    continue;
             } else {
+                /* not useful to search here if next position has same (or lower) cost */
                 if (opt[cur+1].price <= opt[cur].price) continue;
             }