*/
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)
*(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;
*(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;
}
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) */
}
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) */
}
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",