]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
slightly improved compression speed
authorYann Collet <yann.collet.73@gmail.com>
Fri, 29 Jul 2016 22:55:13 +0000 (00:55 +0200)
committerYann Collet <yann.collet.73@gmail.com>
Fri, 29 Jul 2016 22:55:13 +0000 (00:55 +0200)
lib/common/zstd_internal.h
lib/compress/zstd_compress.c
lib/dictBuilder/zdict.c
lib/zstd.h

index 438045b7607ff28849032fbfbdc393126d1d50fe..d0391871b258c060282488303c48a4d976ec918e 100644 (file)
@@ -192,13 +192,13 @@ typedef struct seqDef_s {
 
 
 typedef struct {
+    seqDef* sequencesStart;
     seqDef* sequences;
     BYTE* litStart;
     BYTE* lit;
     BYTE* llCode;
     BYTE* mlCode;
     BYTE* ofCode;
-    U32   nbSeq;
     U32   longLengthID;   /* 0 == no longLength; 1 == Lit.longLength; 2 == Match.longLength; */
     U32   longLengthPos;
     /* opt */
index 49b8b0af582f3e3cc0a4a8ae5c3380ce6f032639..07f23b5ab4ee4c9312b68ed44e48baa2efbe5292 100644 (file)
@@ -82,7 +82,7 @@ size_t ZSTD_compressBound(size_t srcSize) { return FSE_compressBound(srcSize) +
 static void ZSTD_resetSeqStore(seqStore_t* ssPtr)
 {
     ssPtr->lit = ssPtr->litStart;
-    ssPtr->nbSeq = 0;
+    ssPtr->sequences = ssPtr->sequencesStart;
     ssPtr->longLengthID = 0;
 }
 
@@ -312,8 +312,8 @@ static size_t ZSTD_resetCCtx_advanced (ZSTD_CCtx* zc,
         ptr = zc->seqStore.priceTable + ZSTD_OPT_NUM+1;
         zc->seqStore.litLengthSum = 0;
     }
-    zc->seqStore.sequences = (seqDef*)ptr;
-    ptr = zc->seqStore.sequences + maxNbSeq;
+    zc->seqStore.sequencesStart = (seqDef*)ptr;
+    ptr = zc->seqStore.sequencesStart + maxNbSeq;
     zc->seqStore.llCode = (BYTE*) ptr;
     zc->seqStore.mlCode = zc->seqStore.llCode + maxNbSeq;
     zc->seqStore.ofCode = zc->seqStore.mlCode + maxNbSeq;
@@ -545,11 +545,11 @@ void ZSTD_seqToCodes(const seqStore_t* seqStorePtr)
 {
     BYTE const LL_deltaCode = 19;
     BYTE const ML_deltaCode = 36;
-    const seqDef* const sequences = seqStorePtr->sequences;
+    const seqDef* const sequences = seqStorePtr->sequencesStart;
     BYTE* const llCodeTable = seqStorePtr->llCode;
     BYTE* const ofCodeTable = seqStorePtr->ofCode;
     BYTE* const mlCodeTable = seqStorePtr->mlCode;
-    U32 const nbSeq = seqStorePtr->nbSeq;
+    U32 const nbSeq = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart);
     U32 u;
     for (u=0; u<nbSeq; u++) {
         U32 const llv = sequences[u].litLength;
@@ -576,14 +576,14 @@ size_t ZSTD_compressSequences(ZSTD_CCtx* zc,
     FSE_CTable* CTable_OffsetBits = zc->offcodeCTable;
     FSE_CTable* CTable_MatchLength = zc->matchlengthCTable;
     U32 LLtype, Offtype, MLtype;   /* compressed, raw or rle */
-    const seqDef* const sequences = seqStorePtr->sequences;
+    const seqDef* const sequences = seqStorePtr->sequencesStart;
     const BYTE* const ofCodeTable = seqStorePtr->ofCode;
     const BYTE* const llCodeTable = seqStorePtr->llCode;
     const BYTE* const mlCodeTable = seqStorePtr->mlCode;
     BYTE* const ostart = (BYTE*)dst;
     BYTE* const oend = ostart + dstCapacity;
     BYTE* op = ostart;
-    size_t const nbSeq = seqStorePtr->nbSeq;
+    size_t const nbSeq = seqStorePtr->sequences - seqStorePtr->sequencesStart;
     BYTE* seqHead;
 
     /* Compress literals */
@@ -765,7 +765,6 @@ MEM_STATIC void ZSTD_storeSeq(seqStore_t* seqStorePtr, size_t litLength, const v
         printf("Cpos %6u :%5u literals & match %3u bytes at distance %6u \n",
                pos, (U32)litLength, (U32)matchCode+MINMATCH, (U32)offsetCode);
 #endif
-    U32 const nbSeq = seqStorePtr->nbSeq;
     ZSTD_statsUpdatePrices(&seqStorePtr->stats, litLength, (const BYTE*)literals, offsetCode, matchCode);   /* debug only */
 
     /* copy Literals */
@@ -773,17 +772,17 @@ MEM_STATIC void ZSTD_storeSeq(seqStore_t* seqStorePtr, size_t litLength, const v
     seqStorePtr->lit += litLength;
 
     /* literal Length */
-    if (litLength>0xFFFF) { seqStorePtr->longLengthID = 1; seqStorePtr->longLengthPos = nbSeq; }
-    seqStorePtr->sequences[nbSeq].litLength = (U16)litLength;
+    if (litLength>0xFFFF) { seqStorePtr->longLengthID = 1; seqStorePtr->longLengthPos = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart); }
+    seqStorePtr->sequences[0].litLength = (U16)litLength;
 
     /* match offset */
-    seqStorePtr->sequences[nbSeq].offset = offsetCode + 1;
+    seqStorePtr->sequences[0].offset = offsetCode + 1;
 
     /* match Length */
-    if (matchCode>0xFFFF) { seqStorePtr->longLengthID = 2; seqStorePtr->longLengthPos = nbSeq; }
-    seqStorePtr->sequences[nbSeq].matchLength = (U16)matchCode;
+    if (matchCode>0xFFFF) { seqStorePtr->longLengthID = 2; seqStorePtr->longLengthPos = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart); }
+    seqStorePtr->sequences[0].matchLength = (U16)matchCode;
 
-    seqStorePtr->nbSeq++;
+    seqStorePtr->sequences++;
 }
 
 
index d16e1efce3b20e0c28b7728e8ddc54e5857be010..84272d1941dc645e07c5ad28e81b6761ecdcba41 100644 (file)
@@ -594,7 +594,7 @@ static void ZDICT_countEStats(EStats_ress_t esr, ZSTD_parameters params,
         }
 
         /* seqStats */
-        {   U32 const nbSeq = seqStorePtr->nbSeq;
+        {   U32 const nbSeq = (U32)(seqStorePtr->sequences - seqStorePtr->sequencesStart);
             ZSTD_seqToCodes(seqStorePtr);
 
             {   const BYTE* codePtr = seqStorePtr->ofCode;
index 1dded9b4852587af735d333f62cfd7c815f7d510..6b9ed463d1cfdb4be5db54cf1abefb51c742179a 100644 (file)
@@ -80,16 +80,19 @@ ZSTDLIB_API size_t ZSTD_compress( void* dst, size_t dstCapacity,
 
 /*! ZSTD_getDecompressedSize() :
 *   @return : decompressed size if known, 0 otherwise.
-       note 1 : decompressed size could be wrong or intentionally modified !
-                Always ensure result fits within application's authorized limits !
-                Each application can set its own limit, depending on local limitations.
-                For extended interoperability, it is recommended to support at least 8 MB.
-       note 2 : when `0`, if precise failure cause is needed, use ZSTD_getFrameParams() to know more. */
+*      note 1 : decompressed size could be wrong or intentionally modified !
+*               Always ensure result fits within application's authorized limits !
+*               Each application can set its own limit, depending on local restrictions.
+*               For extended interoperability, it is recommended to support at least 8 MB.
+*      note 2 : when `0`, if precise failure cause is needed, use ZSTD_getFrameParams() to know more.
+*      note 3 : when `0`, and if no external guarantee about maximum possible decompressed size,
+*               it's necessary to use "streaming mode" to decompress data. */
 unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize);
 
 /*! ZSTD_decompress() :
     `compressedSize` : must be the _exact_ size of compressed input, otherwise decompression will fail.
-    `dstCapacity` must be equal or larger than originalSize.
+    `dstCapacity` must be equal or larger than originalSize (see ZSTD_getDecompressedSize() ).
+    If maximum possible content size is unknown, use streaming mode to decompress data.
     @return : the number of bytes decompressed into `dst` (<= `dstCapacity`),
               or an errorCode if it fails (which can be tested using ZSTD_isError()) */
 ZSTDLIB_API size_t ZSTD_decompress( void* dst, size_t dstCapacity,