From: Yann Collet Date: Tue, 2 Feb 2016 16:30:37 +0000 (+0100) Subject: changed long length format X-Git-Tag: v0.5.0~1^2~3^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d8e6bddb98a085514982b802fb1c8ce980320fb;p=thirdparty%2Fzstd.git changed long length format --- diff --git a/lib/zstd_compress.c b/lib/zstd_compress.c index 3dd865151..c89d5ca1b 100644 --- a/lib/zstd_compress.c +++ b/lib/zstd_compress.c @@ -718,7 +718,7 @@ _check_compressibility: */ MEM_STATIC void ZSTD_storeSeq(seqStore_t* seqStorePtr, size_t litLength, const BYTE* literals, size_t offsetCode, size_t matchCode) { -#if 0 +#if 0 /* for debug */ static const BYTE* g_start = NULL; if (g_start==NULL) g_start = literals; //if (literals - g_start == 8695) @@ -737,7 +737,13 @@ MEM_STATIC void ZSTD_storeSeq(seqStore_t* seqStorePtr, size_t litLength, const B *(seqStorePtr->dumps++) = (BYTE)(litLength - MaxLL); } else { *(seqStorePtr->dumps++) = 255; - MEM_writeLE32(seqStorePtr->dumps, (U32)litLength); seqStorePtr->dumps += 3; + if (litLength < (1<<15)) { + MEM_writeLE16(seqStorePtr->dumps, (U16)(litLength<<1)); + seqStorePtr->dumps += 2; + } else { + MEM_writeLE32(seqStorePtr->dumps, (U32)((litLength<<1)+1)); + seqStorePtr->dumps += 3; + } } } else *(seqStorePtr->litLength++) = (BYTE)litLength; @@ -751,7 +757,13 @@ MEM_STATIC void ZSTD_storeSeq(seqStore_t* seqStorePtr, size_t litLength, const B *(seqStorePtr->dumps++) = (BYTE)(matchCode - MaxML); } else { *(seqStorePtr->dumps++) = 255; - MEM_writeLE32(seqStorePtr->dumps, (U32)matchCode); seqStorePtr->dumps += 3; + if (matchCode < (1<<15)) { + MEM_writeLE16(seqStorePtr->dumps, (U16)(matchCode<<1)); + seqStorePtr->dumps += 2; + } else { + MEM_writeLE32(seqStorePtr->dumps, (U32)((matchCode<<1)+1)); + seqStorePtr->dumps += 3; + } } } else *(seqStorePtr->matchLength++) = (BYTE)matchCode; } diff --git a/lib/zstd_decompress.c b/lib/zstd_decompress.c index 6061c8741..5d637d2bb 100644 --- a/lib/zstd_decompress.c +++ b/lib/zstd_decompress.c @@ -626,8 +626,9 @@ static void ZSTD_decodeSequence(seq_t* seq, seqState_t* seqState) U32 add = *dumps++; if (add < 255) litLength += add; else { - litLength = MEM_readLE32(dumps) & 0xFFFFFF; /* no pb : dumps is always followed by seq tables > 1 byte */ - dumps += 3; + litLength = MEM_readLE32(dumps) & 0xFFFFFF; /* no risk : dumps is always followed by seq tables > 1 byte */ + if (litLength&1) litLength>>=1, dumps += 3; + else litLength = (U16)(litLength)>>1, dumps += 2; } if (dumps >= de) dumps = de-1; /* late correction, to avoid read overflow (data is now corrupted anyway) */ } @@ -659,7 +660,8 @@ static void ZSTD_decodeSequence(seq_t* seq, seqState_t* seqState) if (add < 255) matchLength += add; else { matchLength = MEM_readLE32(dumps) & 0xFFFFFF; /* no pb : dumps is always followed by seq tables > 1 byte */ - dumps += 3; + if (matchLength&1) matchLength>>=1, dumps += 3; + else matchLength = (U16)(matchLength)>>1, dumps += 2; } if (dumps >= de) dumps = de-1; /* late correction, to avoid read overflow (data is now corrupted anyway) */ } @@ -671,7 +673,7 @@ static void ZSTD_decodeSequence(seq_t* seq, seqState_t* seqState) seq->matchLength = matchLength; seqState->dumps = dumps; -#if 0 +#if 0 /* debug */ { static U64 totalDecoded = 0; printf("pos %6u : %3u literals & match %3u bytes at distance %6u \n",