]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Addressing comments
authorBimba Shrestha <bimbashrestha@fb.com>
Thu, 19 Sep 2019 22:25:20 +0000 (15:25 -0700)
committerBimba Shrestha <bimbashrestha@fb.com>
Thu, 19 Sep 2019 22:25:20 +0000 (15:25 -0700)
lib/compress/zstd_compress.c
lib/zstd.h

index acb3b15e87412b6ea829975b65d84c6a591d1ef4..ce352acde158a542d4740df7510c354812872a79 100644 (file)
@@ -2302,7 +2302,7 @@ static void ZSTD_copyBlockSequences(ZSTD_CCtx* zc)
             }
             assert(repIdx >= -3);
             outSeqs[i].offset = repIdx >= 0 ? outSeqs[repIdx].offset : repStartValue[-repIdx - 1];
-            if (outSeqs[i].offset == 4) {
+            if (outSeqs[i].rep == 4) {
                 --outSeqs[i].offset;
             }
         } else {
@@ -2319,9 +2319,6 @@ static void ZSTD_copyBlockSequences(ZSTD_CCtx* zc)
 size_t ZSTD_getSequences(ZSTD_CCtx* zc, ZSTD_Sequence* outSeqs,
     size_t outSeqsSize, const void* src, size_t srcSize)
 {
-    const size_t dstCapacity = ZSTD_compressBound(srcSize * sizeof(void*));
-    void* dst = ZSTD_malloc(dstCapacity, ZSTD_defaultCMem);
-
     SeqCollector seqCollector;
     seqCollector.collectSequences = 1;
     seqCollector.seqStart = outSeqs;
@@ -2329,8 +2326,8 @@ size_t ZSTD_getSequences(ZSTD_CCtx* zc, ZSTD_Sequence* outSeqs,
     seqCollector.maxSequences = outSeqsSize;
     zc->seqCollector = seqCollector;
 
-    ZSTD_compress2(zc, dst, dstCapacity, src, srcSize);
-    ZSTD_free(dst, ZSTD_defaultCMem);
+    /* We never write to dst when collecing sequences so setting dst = src is harmless */
+    ZSTD_compress2(zc, (void*)src, srcSize, src, srcSize);
     return zc->seqCollector.seqIndex;
 }
 
index 217a6d3506eef9656e90cc6c948b7dd8cd387053..836aa7238c35199e13e2b58ae565a1a0f94ab4f1 100644 (file)
@@ -1078,11 +1078,21 @@ 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; /* 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 */
+    unsigned int matchPos; /* Match pos in dst */
+    /* If seqDef.offset > 3, then this is seqDef.offset - 3
+     * If seqDef.offset < 3, then this is the corresponding repeat offset
+     * But if seqDef.offset < 3 and litLength == 0, this is the
+     *   repeat offset before the corresponding repeat offset
+     * And if seqDef.offset == 3 and litLength == 0, this is the
+     *   most recent repeat offset - 1
+     */
+    unsigned int offset;
+    unsigned int litLength; /* Literal length */
+    unsigned int matchLength; /* Match length */
+    /* 0 when seq not rep and seqDef.offset otherwise
+     * when litLength == 0 this will be <= 4, otherwise <= 3 like normal
+     */
+    unsigned int rep;
 } ZSTD_Sequence;
 
 typedef struct {