]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[opt] Explain why we don't include literals price
authorNick Terrell <terrelln@fb.com>
Thu, 5 Mar 2020 00:29:19 +0000 (16:29 -0800)
committerNick Terrell <terrelln@fb.com>
Thu, 5 Mar 2020 00:29:19 +0000 (16:29 -0800)
lib/compress/zstd_opt.c

index 44a13ddb77850fd98c4454aa3bffb81c4278bb1b..896365fc8779ed1aa56e7388cc97d15920a24c9a 100644 (file)
@@ -881,6 +881,11 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms,
             { U32 i ; for (i=0; i<ZSTD_REP_NUM; i++) opt[0].rep[i] = rep[i]; }
             opt[0].mlen = 0;  /* means is_a_literal */
             opt[0].litlen = litlen;
+            /* We don't need to include the actual price of the literals because
+             * it is static for the duration of the forward pass, and is included
+             * in every price. We include the literal length to avoid negative
+             * prices when we subtract the previous literal length.
+             */
             opt[0].price = ZSTD_litLengthPrice(litlen, optStatePtr, optLevel);
 
             /* large match -> immediate encoding */