]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Add algorithm to remove all delimiters
authorsenhuang42 <senhuang96@fb.com>
Mon, 2 Nov 2020 15:46:52 +0000 (10:46 -0500)
committersenhuang42 <senhuang96@fb.com>
Mon, 2 Nov 2020 15:46:52 +0000 (10:46 -0500)
lib/compress/zstd_compress.c
lib/zstd.h

index 12b5a32e74439383897dacbcb4afc284f330511d..1f274622ea25e75a1c05b613027ae6edd6d060df 100644 (file)
@@ -2567,6 +2567,24 @@ size_t ZSTD_getSequences(ZSTD_CCtx* zc, ZSTD_Sequence* outSeqs,
 
     ZSTD_compress2(zc, dst, dstCapacity, src, srcSize);
     ZSTD_customFree(dst, ZSTD_defaultCMem);
+
+    if (format == ZSTD_sf_noBlockDelimiters) {
+        /* Merge the dummy block delimiters */
+        size_t i = 0;
+        size_t totalSeqs = zc->seqCollector.seqIndex;
+        for (; i < totalSeqs; ++i) {
+            if (seqCollector.seqStart[i].offset == 0 && seqCollector.seqStart[i].matchLength == 0) {
+                /* Merge the block boundary or last literals */
+                if (i != totalSeqs-1) {
+                    /* Add last literals to next sequence, then "delete" this sequence */
+                    seqCollector.seqStart[i+1].litLength += seqCollector.seqStart[i].litLength;
+                    memmove(seqCollector.seqStart+i, seqCollector.seqStart+i+1, (totalSeqs-i-1)*sizeof(ZSTD_sequence));
+                }
+                totalSeqs--;
+            }
+        }
+        zc->seqCollector.seqIndex = totalSeqs;
+    }
     return zc->seqCollector.seqIndex;
 }
 
index 3809a033b00016d0f3e4cffc2aa48b61cbb50594..4158c4ac08c249ee73f9a7983e874ab72400bfa6 100644 (file)
@@ -1309,9 +1309,9 @@ typedef enum {
  * 
  * If invoked with ZSTD_sf_noBlockDelimiters, sequences will still be generated
  * on a per-block basis, but any last literals of a block will be merged into the
- * last literals of the first sequence in the next block with the exception of the
- * final segment of last literals. As such, the final generated result has no
- * explicit representation of block boundaries.
+ * last literals of the first sequence in the next block.
+ * As such, the final generated result has no explicit representation of block boundaries,
+ * and the final last literals segment is not represented in the sequences.
  * 
  * zc can be used to insert custom compression params.
  * This function invokes ZSTD_compress2