From: Yann Collet Date: Thu, 7 Apr 2016 15:19:00 +0000 (+0200) Subject: minor compression speed optimization X-Git-Tag: v0.6.0^2~17^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d39357bc4a030819778e2ec054825cb72a70af3;p=thirdparty%2Fzstd.git minor compression speed optimization --- diff --git a/lib/zstd_compress.c b/lib/zstd_compress.c index 0d84176b3..e6b13ca3e 100644 --- a/lib/zstd_compress.c +++ b/lib/zstd_compress.c @@ -80,6 +80,7 @@ static void ZSTD_resetSeqStore(seqStore_t* ssPtr) ssPtr->lit = ssPtr->litStart; ssPtr->litLength = ssPtr->litLengthStart; ssPtr->matchLength = ssPtr->matchLengthStart; + ssPtr->longLengthID = 0; } @@ -620,14 +621,16 @@ void ZSTD_seqToCodes(const seqStore_t* seqStorePtr, size_t const nbSeq) 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24 }; const BYTE LL_deltaCode = 19; - U16* const llTable = seqStorePtr->litLengthStart; + const U16* const llTable = seqStorePtr->litLengthStart; BYTE* const llCodeTable = seqStorePtr->llCodeStart; size_t u; for (u=0; ulongLength; llTable[u] = (U16)ll; } + U32 const ll = llTable[u]; llCodeTable[u] = (ll>63) ? (BYTE)ZSTD_highbit(ll) + LL_deltaCode : LL_Code[ll]; - } } + } + if (seqStorePtr->longLengthID==1) + llCodeTable[seqStorePtr->longLengthPos] = MaxLL; + } /* Offset codes */ { const U32* const offsetTable = seqStorePtr->offsetStart; @@ -646,14 +649,16 @@ void ZSTD_seqToCodes(const seqStore_t* seqStorePtr, size_t const nbSeq) 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42 }; const BYTE ML_deltaCode = 36; - U16* const mlTable = seqStorePtr->matchLengthStart; + const U16* const mlTable = seqStorePtr->matchLengthStart; BYTE* const mlCodeTable = seqStorePtr->mlCodeStart; size_t u; for (u=0; ulongLength; mlTable[u] = (U16)ml; } + U32 const ml = mlTable[u]; mlCodeTable[u] = (ml>127) ? (BYTE)ZSTD_highbit(ml) + ML_deltaCode : ML_Code[ml]; - } } + } + if (seqStorePtr->longLengthID==2) + mlCodeTable[seqStorePtr->longLengthPos] = MaxML; + } } @@ -864,15 +869,15 @@ MEM_STATIC void ZSTD_storeSeq(seqStore_t* seqStorePtr, size_t litLength, const B seqStorePtr->lit += litLength; /* literal Length */ - if (litLength>=65535) { *(seqStorePtr->litLength++) = 65535; seqStorePtr->longLength = (U32)litLength; } - else *seqStorePtr->litLength++ = (U16)litLength; + if (litLength>0xFFFF) { seqStorePtr->longLengthID = 1; seqStorePtr->longLengthPos = (U32)(seqStorePtr->litLength - seqStorePtr->litLengthStart); } + *seqStorePtr->litLength++ = (U16)litLength; /* match offset */ *(seqStorePtr->offset++) = (U32)offsetCode + 1; /* match Length */ - if (matchCode>=65535) { *(seqStorePtr->matchLength++) = 65535; seqStorePtr->longLength = (U32)matchCode; } - else *seqStorePtr->matchLength++ = (U16)matchCode; + if (matchCode>0xFFFF) { seqStorePtr->longLengthID = 2; seqStorePtr->longLengthPos = (U32)(seqStorePtr->matchLength - seqStorePtr->matchLengthStart); } + *seqStorePtr->matchLength++ = (U16)matchCode; } diff --git a/lib/zstd_internal.h b/lib/zstd_internal.h index 9e6ffcafb..31a99cbde 100644 --- a/lib/zstd_internal.h +++ b/lib/zstd_internal.h @@ -222,7 +222,8 @@ typedef struct { U16* matchLengthStart; U16* matchLength; BYTE* mlCodeStart; - U32 longLength; + U32 longLengthID; /* 0 == no longLength; 1 == Lit.longLength; 2 == Match.longLength; */ + U32 longLengthPos; /* opt */ ZSTD_optimal_t* priceTable; ZSTD_match_t* matchTable;