From: senhuang42 Date: Sun, 27 Sep 2020 02:14:21 +0000 (-0400) Subject: Add re-copying of ldmSeqStore after processing X-Git-Tag: v1.4.7~57^2~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84009a076ad4f23de5eef76a84ac34be47ae5fef;p=thirdparty%2Fzstd.git Add re-copying of ldmSeqStore after processing --- diff --git a/lib/compress/zstd_ldm.c b/lib/compress/zstd_ldm.c index c68693bd6..42e6aa2d8 100644 --- a/lib/compress/zstd_ldm.c +++ b/lib/compress/zstd_ldm.c @@ -580,6 +580,7 @@ size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore, size_t lastLLSize; ms->ldmSeqStore = *rawSeqStore; /* copy current seqStore */ lastLLSize = blockCompressor(ms, seqStore, rep, src, srcSize); + rawSeqStore->pos = ms->ldmSeqStore.pos; return lastLLSize; } diff --git a/lib/compress/zstd_opt.c b/lib/compress/zstd_opt.c index 0a17374ae..f938cce8e 100644 --- a/lib/compress/zstd_opt.c +++ b/lib/compress/zstd_opt.c @@ -806,6 +806,7 @@ static rawSeq ldm_splitSequence(rawSeqStore_t* ldmSeqStore, U32 remainingBytes) if (remainingBytes >= currSeq.litLength + currSeq.matchLength) { printf("NO SPLIT\n"); ldmSeqStore->pos++; + printf("pos is now: %u\n", ldmSeqStore->pos); return currSeq; } /* Need a split */ @@ -831,8 +832,9 @@ static int ldm_getNextMatch(rawSeqStore_t* ldmSeqStore, U32* matchOffset, U32 currPosInBlock, U32 remainingBytes) { rawSeq seq = ldm_splitSequence(ldmSeqStore, remainingBytes); - if (seq.offset == 0) { + if (seq.offset == 0 || ldmSeqStore->pos > ldmSeqStore->size) { // Don't use the LDM for the rest of the block (there is none) + printf("No ldm left in the block\n"); *matchStartPosInBlock = UINT32_MAX; *matchEndPosInBlock = UINT32_MAX; return 1; @@ -841,6 +843,7 @@ static int ldm_getNextMatch(rawSeqStore_t* ldmSeqStore, *matchStartPosInBlock = currPosInBlock + seq.litLength; *matchEndPosInBlock = *matchStartPosInBlock + seq.matchLength; *matchOffset = seq.offset; + printf("New match range in block is: (%u, %u) with of: %u where currPosInBlock: %u\n", *matchStartPosInBlock, *matchEndPosInBlock, *matchOffset, currPosInBlock); return 0; } @@ -860,6 +863,7 @@ static void ldm_maybeAddLdm(ZSTD_match_t* matches, U32* nbMatches, if (matchLengthAdjusted >= matches[*nbMatches-1].len) { printf("Adding LDM with of: %u, ml: %u\n", matchOffsetAdjusted, matchLengthAdjusted); + /* Add sifting */ matches[*nbMatches].len = matchLengthAdjusted; matches[*nbMatches].off = matchOffsetAdjusted; (*nbMatches)++; @@ -875,8 +879,7 @@ static void ldm_handleLdm(rawSeqStore_t* ldmSeqStore, ZSTD_match_t* matches, U32 matchEndPosInBlock, matchOffset, currPosInBlock, remainingBytes); } - if (ldmSeqStore->pos <= ldmSeqStore->size) - ldm_maybeAddLdm(matches, nbMatches, *matchStartPosInBlock, *matchEndPosInBlock, *matchOffset, currPosInBlock); + ldm_maybeAddLdm(matches, nbMatches, *matchStartPosInBlock, *matchEndPosInBlock, *matchOffset, currPosInBlock); } @@ -936,11 +939,7 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms, U32 ldmStartPosInBlock = 0; U32 ldmEndPosInBlock = 0; U32 ldmOffset = 0; - if (ms->ldmSeqStore.size != 0) { - ldm_getNextMatch(&ms->ldmSeqStore, &ldmStartPosInBlock, - &ldmEndPosInBlock, &ldmOffset, - (U32)(ip-istart), (U32)(iend - ip)); - } + /* init */ DEBUGLOG(5, "ZSTD_compressBlock_opt_generic: current=%u, prefix=%u, nextToUpdate=%u", @@ -948,7 +947,12 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms, assert(optLevel <= 2); ZSTD_rescaleFreqs(optStatePtr, (const BYTE*)src, srcSize, optLevel); ip += (ip==prefixStart); - + + if (ms->ldmSeqStore.size != 0) { + ldm_getNextMatch(&ms->ldmSeqStore, &ldmStartPosInBlock, + &ldmEndPosInBlock, &ldmOffset, + (U32)(ip-istart), (U32)(iend - ip)); + } /* Match Loop */ while (ip < ilimit) { U32 cur, last_pos = 0;