From: senhuang42 Date: Sat, 26 Sep 2020 16:16:15 +0000 (-0400) Subject: Implement ldm_getNextMatch() X-Git-Tag: v1.4.7~57^2~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84777059d24dc9a82b52bab7c68985e1b23ff3e3;p=thirdparty%2Fzstd.git Implement ldm_getNextMatch() --- diff --git a/lib/compress/zstd_opt.c b/lib/compress/zstd_opt.c index 6c8e8cc1d..c131e6f18 100644 --- a/lib/compress/zstd_opt.c +++ b/lib/compress/zstd_opt.c @@ -821,8 +821,20 @@ static rawSeq ldm_splitSequence(rawSeqStore_t* ldmSeqStore, U32 remainingBytes) /* Returns 1 if the rest of the block is just LDM literals */ static int ldm_getNextMatch(rawSeqStore_t* ldmSeqStore, U32* matchStartPosInBlock, U32* matchEndPosInBlock, + U32* matchOffset, U32 currPosInBlock, U32 remainingBytes) { - int ret = ldm_splitSequence(ldmSeqStore, remainingBytes); + rawSeq seq = ldm_splitSequence(ldmSeqStore, remainingBytes); + if (seq.offset == 0) { + // Don't use the LDM for the rest of the block (there is none) + *matchStartPosInBlock = UINT32_MAX; + *matchEndPosInBlock = UINT32_MAX; + return 1; + } + + *matchStartPosInBlock = currPosInBlock + seq.litLength; + *matchEndPosInBlock = *matchStartPosInBlock + seq.matchLength; + *matchOffset = seq.offset; + return 0; } /* Adds an LDM if it's long enough */ @@ -899,8 +911,9 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms, ZSTD_match_t* const matches = optStatePtr->matchTable; ZSTD_optimal_t lastSequence; - U32 matchStartPosInBlock = 0; - U32 matchEndPosInBlock = 0; + U32 ldmStartPosInBlock = 0; + U32 ldmEndPosInBlock = 0; + U32 ldmOffset = 0; ldm_getNextMatch(matchStartPosInBlock, matchEndPosInBlock, (U32)(iend - ip)); /* init */