]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
replaced FSE_count by FSE_count_simple 1127/head
authorYann Collet <cyan@fb.com>
Fri, 11 May 2018 22:54:06 +0000 (15:54 -0700)
committerYann Collet <cyan@fb.com>
Fri, 11 May 2018 23:03:37 +0000 (16:03 -0700)
to reduce usage of stack memory.

Also : tweaked a few comments, as suggested by @terrelln

lib/compress/zstd_compress_internal.h
lib/compress/zstd_opt.c

index 25d3137a2d3a0518a8173e2dbb650a184e058b49..0f1830a5e691a28f507a88611a39388e15d7197c 100644 (file)
@@ -97,8 +97,8 @@ typedef struct {
     U32  log2matchLengthSum;     /* pow2 to compare log2(mlfreq) to */
     U32  log2offCodeSum;         /* pow2 to compare log2(offreq) to */
     /* end : updated by ZSTD_setLog2Prices */
-    ZSTD_OptPrice_e priceType;   /* prices follow a pre-defined cost structure, statistics are irrelevant */
-    const ZSTD_entropyCTables_t* symbolCosts;  /* pre-calculated symbol costs, from dictionary */
+    ZSTD_OptPrice_e priceType;   /* prices can be determined dynamically, or follow dictionary statistics, or a pre-defined cost structure */
+    const ZSTD_entropyCTables_t* symbolCosts;  /* pre-calculated dictionary statistics */
 } optState_t;
 
 typedef struct {
index 29c4c913671c38cf45bce236a552ea385feeb36d..76144f7303c0fdc713a277756e17f4d23f3e34ee 100644 (file)
@@ -97,9 +97,9 @@ static void ZSTD_rescaleFreqs(optState_t* const optPtr,
         } else {  /* not a dictionary */
 
             assert(optPtr->litFreq != NULL);
-            optPtr->litSum = 0;
             {   unsigned lit = MaxLit;
-                FSE_count(optPtr->litFreq, &lit, src, srcSize);   /* use raw first block to init statistics */
+                FSE_count_simple(optPtr->litFreq, &lit, src, srcSize);   /* use raw first block to init statistics */
+                optPtr->litSum = 0;
                 for (lit=0; lit<=MaxLit; lit++) {
                     optPtr->litFreq[lit] = 1 + (optPtr->litFreq[lit] >> (ZSTD_FREQ_DIV+1));
                     optPtr->litSum += optPtr->litFreq[lit];
@@ -244,7 +244,7 @@ static int ZSTD_litLengthContribution(U32 const litLength, const optState_t* con
     /* dynamic statistics */
     {   U32 const llCode = ZSTD_LLcode(litLength);
         int const contribution = (LL_bits[llCode]
-                        + ZSTD_highbit32(optPtr->litLengthFreq[0]+1)
+                        + ZSTD_highbit32(optPtr->litLengthFreq[0]+1) /* note: log2litLengthSum cancels out with following one */
                         - ZSTD_highbit32(optPtr->litLengthFreq[llCode]+1))
                         * BITCOST_MULTIPLIER;
 #if 1