]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
zeroise freq table with memset()
authorYann Collet <cyan@fb.com>
Wed, 27 Jun 2018 00:24:41 +0000 (17:24 -0700)
committerYann Collet <cyan@fb.com>
Wed, 27 Jun 2018 00:24:41 +0000 (17:24 -0700)
improves decoding speed by ~5% in github_users sample set

lib/common/entropy_common.c

index 33fd04bd660607cd11b2a1f06d8a5cf65cc1ef66..b12944e1de93ad10a0349fd9075bb0258128697c 100644 (file)
@@ -85,6 +85,8 @@ size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* t
     }   }
     assert(hbSize >= 4);
 
+    /* init */
+    memset(normalizedCounter, 0, (*maxSVPtr+1) * sizeof(normalizedCounter[0]));   /* all symbols not present in NCount have a frequency of 0 */
     bitStream = MEM_readLE32(ip);
     nbBits = (bitStream & 0xF) + FSE_MIN_TABLELOG;   /* extract tableLog */
     if (nbBits > FSE_TABLELOG_ABSOLUTE_MAX) return ERROR(tableLog_tooLarge);
@@ -156,11 +158,6 @@ size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* t
     }   }   /* while ((remaining>1) & (charnum<=*maxSVPtr)) */
     if (remaining != 1) return ERROR(corruption_detected);
     if (bitCount > 32) return ERROR(corruption_detected);
-    /* zeroise the rest */
-    {   unsigned symbNb = charnum;
-        for (symbNb=charnum; symbNb <= *maxSVPtr; symbNb++)
-            normalizedCounter[symbNb] = 0;
-    }
     *maxSVPtr = charnum-1;
 
     ip += (bitCount+7)>>3;