]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
zstd_opt.h: small improvement in compression ratio
authorPrzemyslaw Skibinski <inikep@gmail.com>
Thu, 20 Oct 2016 09:49:02 +0000 (11:49 +0200)
committerPrzemyslaw Skibinski <inikep@gmail.com>
Thu, 20 Oct 2016 09:49:02 +0000 (11:49 +0200)
lib/compress/zstd_opt.h

index cea67056a570bcb79838a215fc971e65b559304d..8a436df42f25cfd2bae37e392672071d6159a4aa 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
+ * Copyright (c) 2016-present, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
  * All rights reserved.
  *
  * This source code is licensed under the BSD-style license found in the
@@ -401,7 +401,6 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
     ZSTD_rescaleFreqs(seqStorePtr);
     ip += (ip==prefixStart);
     { U32 i; for (i=0; i<ZSTD_REP_NUM; i++) rep[i]=ctx->rep[i]; }
-    //inr = ip;
 
     /* Match Loop */
     while (ip < ilimit) {
@@ -511,20 +510,20 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
 
                        best_off = i - (opt[cur].mlen != 1);
 
-                       if (opt[cur].mlen == 1) {
-                            litlen = opt[cur].litlen;
-                            if (cur > litlen) {
-                                price = opt[cur - litlen].price + ZSTD_getPrice(seqStorePtr, litlen, inr-litlen, best_off, mlen - MINMATCH);
-                            } else
-                                price = ZSTD_getPrice(seqStorePtr, litlen, anchor, best_off, mlen - MINMATCH);
-                        } else {
-                            litlen = 0;
-                            price = opt[cur].price + ZSTD_getPrice(seqStorePtr, 0, NULL, best_off, mlen - MINMATCH);
-                        }
+                       if (mlen > best_mlen) best_mlen = mlen;
 
-                        if (mlen > best_mlen) best_mlen = mlen;
+                       do {
+                           if (opt[cur].mlen == 1) {
+                                litlen = opt[cur].litlen;
+                                if (cur > litlen) {
+                                    price = opt[cur - litlen].price + ZSTD_getPrice(seqStorePtr, litlen, inr-litlen, best_off, mlen - MINMATCH);
+                                } else
+                                    price = ZSTD_getPrice(seqStorePtr, litlen, anchor, best_off, mlen - MINMATCH);
+                            } else {
+                                litlen = 0;
+                                price = opt[cur].price + ZSTD_getPrice(seqStorePtr, 0, NULL, best_off, mlen - MINMATCH);
+                            }
 
-                        do {
                             if (cur + mlen > last_pos || price <= opt[cur + mlen].price)
                                 SET_PRICE(cur + mlen, mlen, i, litlen, price);
                             mlen--;
@@ -657,7 +656,6 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
     ctx->nextToUpdate3 = ctx->nextToUpdate;
     ZSTD_rescaleFreqs(seqStorePtr);
     ip += (ip==prefixStart);
-    //inr = ip;
 
     /* Match Loop */
     while (ip < ilimit) {
@@ -666,7 +664,6 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
         U32 current = (U32)(ip-base);
         memset(opt, 0, sizeof(ZSTD_optimal_t));
         last_pos = 0;
-        //inr = ip;
         opt[0].litlen = (U32)(ip - anchor);
 
         /* check repCode */