]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Add simple API for converting ZSTD_Sequence into seqStore 2715/head
authorsenhuang42 <senhuang96@fb.com>
Wed, 23 Jun 2021 15:21:14 +0000 (11:21 -0400)
committersenhuang42 <senhuang96@fb.com>
Wed, 23 Jun 2021 16:10:48 +0000 (12:10 -0400)
lib/compress/zstd_compress.c

index d7ae6d8260c7c2843d478c6929112a52a5f9d1c9..8ee46fd3ffb7482c8905ada64f9faebce6f78683 100644 (file)
@@ -3721,6 +3721,16 @@ static size_t ZSTD_compressBlock_splitBlock(ZSTD_CCtx* zc,
     return cSize;
 }
 
+/* ZSTD_convertBlockSequencesToSeqStore()
+ * Converts an array of ZSTD_Sequence* with the corresponding original src buffer into 
+ * the seqStore of a cctx.
+ * 
+ * Returns 0 on success, ZSTD_error on failure.
+ */
+static UNUSED_ATTR size_t ZSTD_convertBlockSequencesToSeqStore(ZSTD_CCtx* cctx,
+                                  const ZSTD_Sequence* inSeqs, size_t inSeqsSize,
+                                  const void* src, size_t srcSize);
+
 static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc,
                                         void* dst, size_t dstCapacity,
                                         const void* src, size_t srcSize, U32 frame)
@@ -3757,12 +3767,6 @@ static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc,
             zc->entropyWorkspace, ENTROPY_WORKSPACE_SIZE /* statically allocated in resetCCtx */,
             zc->bmi2);
 
-    if (zc->seqCollector.collectSequences) {
-        ZSTD_copyBlockSequences(zc);
-        return 0;
-    }
-
-
     if (frame &&
         /* We don't want to emit our first block as a RLE even if it qualifies because
          * doing so will cause the decoder (cli only) to throw a "should consume all input error."
@@ -5821,6 +5825,13 @@ static size_t ZSTD_copySequencesToSeqStoreExplicitBlockDelim(ZSTD_CCtx* cctx, ZS
     return 0;
 }
 
+static size_t ZSTD_convertBlockSequencesToSeqStore(ZSTD_CCtx* cctx,
+                                  const ZSTD_Sequence* inSeqs, size_t inSeqsSize,
+                                  const void* src, size_t srcSize) {
+    ZSTD_sequencePosition dummySeqPos = {0, 0, 0};
+    return ZSTD_copySequencesToSeqStoreExplicitBlockDelim(cctx, &dummySeqPos, inSeqs, inSeqsSize, src, srcSize);
+}
+
 /* Returns the number of bytes to move the current read position back by. Only non-zero
  * if we ended up splitting a sequence. Otherwise, it may return a ZSTD error if something
  * went wrong.