From ade8586ce6175d1cd2df9e3902d79197f3a309c4 Mon Sep 17 00:00:00 2001 From: "W. Felix Handte" Date: Thu, 14 Jun 2018 14:53:04 -0400 Subject: [PATCH] Find `mls == 3` Matches --- lib/compress/zstd_opt.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/compress/zstd_opt.c b/lib/compress/zstd_opt.c index f638c150a..974802e17 100644 --- a/lib/compress/zstd_opt.c +++ b/lib/compress/zstd_opt.c @@ -603,7 +603,36 @@ U32 ZSTD_insertBtAndGetAllMatches ( (ip+mlen == iLimit) ) { /* best possible length */ ms->nextToUpdate = current+1; /* skip insertion */ return 1; - } } } } + } + } + } else if (dictMode == ZSTD_dictMatchState) { + /* should we perform this search even if the working ctx search + * found a match? */ + U32 const hashLog3 = ms->hashLog3; + size_t const hash3 = ZSTD_hash3Ptr(ip, hashLog3); + U32 const dmsMatchIndex3 = dms->hashTable3[hash3]; + if (dmsMatchIndex3 >= dmsLowLimit) { + const BYTE* const match = dmsBase + dmsMatchIndex3; + size_t mlen = ZSTD_count_2segments(ip, match, iLimit, dmsEnd, prefixStart); + if (mlen >= mls) { + U32 const matchIndex3 = dmsMatchIndex3 + dmsIndexDelta; + DEBUGLOG(8, "found small dms match with hlog3, of length %u", + (U32)mlen); + bestLength = mlen; + assert(current > matchIndex3); + assert(mnum==0); /* no prior solution */ + matches[0].off = (current - matchIndex3) + ZSTD_REP_MOVE; + matches[0].len = (U32)mlen; + mnum = 1; + if ( (mlen > sufficient_len) | + (ip+mlen == iLimit) ) { /* best possible length */ + ms->nextToUpdate = current+1; /* skip insertion */ + return 1; + } + } + } + } + } hashTable[h] = current; /* Update Hash Table */ -- 2.47.2