]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Bailing early when collecting sequences and documentation
authorBimba Shrestha <bimbashrestha@fb.com>
Mon, 16 Sep 2019 15:26:21 +0000 (08:26 -0700)
committerBimba Shrestha <bimbashrestha@fb.com>
Mon, 16 Sep 2019 15:26:21 +0000 (08:26 -0700)
lib/compress/zstd_compress.c
lib/zstd.h

index 849a9f42c7f7d56437b595d785b261db2283fc32..833ae8383d219873ebff441cffe56536ad4322c6 100644 (file)
@@ -2315,10 +2315,6 @@ static void ZSTD_copyBlockSequences(ZSTD_CCtx* zc)
     zc->seqCollector.seqIndex += seqsSize;
 }
 
-/* We call compress2() and collect sequences after each block
- * compression. The function stores the ZSTD_Sequences in outSeqs
- * and returns the number of collected sequences from all blocks.
- */
 size_t ZSTD_getSequences(ZSTD_CCtx* zc, ZSTD_Sequence* outSeqs,
     size_t outSeqsSize, const void* src, size_t srcSize)
 {
@@ -2351,6 +2347,11 @@ static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc,
         if (bss == ZSTDbss_noCompress) { cSize = 0; goto out; }
     }
 
+    if (zc->seqCollector.collectSequences) {
+        ZSTD_copyBlockSequences(zc);
+        return 0;
+    }
+
     /* encode sequences and literals */
     cSize = ZSTD_compressSequences(&zc->seqStore,
             &zc->blockState.prevCBlock->entropy, &zc->blockState.nextCBlock->entropy,
@@ -2360,10 +2361,6 @@ static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc,
             zc->entropyWorkspace, HUF_WORKSPACE_SIZE /* statically allocated in resetCCtx */,
             zc->bmi2);
 
-    if (zc->seqCollector.collectSequences) {
-        ZSTD_copyBlockSequences(zc);
-    }
-
 out:
     if (!ZSTD_isError(cSize) && cSize != 0) {
         /* confirm repcodes and entropy tables when emitting a compressed block */
index 97feb77d562aa04356ec5c3284cdcf86f6e69b7d..3e737d8fe5c66960a33a25bb50c085d6da0746a3 100644 (file)
@@ -1073,11 +1073,11 @@ ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
 typedef struct ZSTD_CCtx_params_s ZSTD_CCtx_params;
 
 typedef struct {
-    unsigned int matchPos;
-    unsigned int offset;
-    unsigned int litLength;
-    unsigned int matchLength;
-    unsigned int rep;
+    unsigned int matchPos; /* match pos in dst */
+    unsigned int offset; /* offset taking into account rep (different from seqdef) */
+    unsigned int litLength; /* literal length */
+    unsigned int matchLength; /* match length */
+    unsigned int rep; /* 0 when seq not rep and seqDef.offset otherwise */
 } ZSTD_Sequence;
 
 typedef struct {
@@ -1218,6 +1218,12 @@ ZSTDLIB_API unsigned long long ZSTD_decompressBound(const void* src, size_t srcS
  *           or an error code (if srcSize is too small) */
 ZSTDLIB_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
 
+/*! ZSTD_getSequences() :
+ * Extract sequences from the sequence store
+ * zc can be used to insert custom compression params.
+ * This function invokes ZSTD_compress2
+ * @return : number of sequences extracted
+ */
 ZSTDLIB_API size_t ZSTD_getSequences(ZSTD_CCtx* zc, ZSTD_Sequence* outSeqs,
     size_t outSeqsSize, const void* src, size_t srcSize);