Reduce the number of literals required at the end of a compressed block

This commit is contained in:
emmanuel-marty 2019-04-05 09:28:16 +02:00
parent bfaa3790d0
commit c86d38ba63
2 changed files with 9 additions and 7 deletions

View File

@ -115,8 +115,8 @@ static inline FORCE_INLINE int lzsa_expand_match_slow(const unsigned char **ppIn
int nMaxFast = nMatchLen; int nMaxFast = nMatchLen;
if (nMaxFast > (pCurOutData - pSrc)) if (nMaxFast > (pCurOutData - pSrc))
nMaxFast = (int)(pCurOutData - pSrc); nMaxFast = (int)(pCurOutData - pSrc);
if ((pCurOutData + nMaxFast) > pOutDataFastEnd) if ((pCurOutData + nMaxFast) > (pOutDataFastEnd - 15))
nMaxFast = (int)(pOutDataFastEnd - pCurOutData); nMaxFast = (int)(pOutDataFastEnd - 15 - pCurOutData);
if (nMaxFast > 0) { if (nMaxFast > 0) {
const unsigned char *pCopySrc = pSrc; const unsigned char *pCopySrc = pSrc;
@ -202,7 +202,7 @@ int lzsa_expand_block(const unsigned char *pInBlock, int nBlockSize, unsigned ch
return -1; return -1;
int nMatchLen = (int)((unsigned int)(token & 0x0f)); int nMatchLen = (int)((unsigned int)(token & 0x0f));
if (nMatchLen < (16 - MIN_MATCH_SIZE + 1) && (pSrc + MIN_MATCH_SIZE + nMatchLen) < pCurOutData) { if (nMatchLen < (16 - MIN_MATCH_SIZE + 1) && (pSrc + MIN_MATCH_SIZE + nMatchLen) < pCurOutData && pCurOutData < pOutDataFastEnd) {
memcpy(pCurOutData, pSrc, 16); memcpy(pCurOutData, pSrc, 16);
pCurOutData += (MIN_MATCH_SIZE + nMatchLen); pCurOutData += (MIN_MATCH_SIZE + nMatchLen);
} }

View File

@ -44,6 +44,9 @@
#define LEAVE_ALONE_MATCH_SIZE 1000 #define LEAVE_ALONE_MATCH_SIZE 1000
#define LAST_MATCH_OFFSET 4
#define LAST_LITERALS 1
/** One match */ /** One match */
typedef struct _lzsa_match { typedef struct _lzsa_match {
unsigned short length; unsigned short length;
@ -357,12 +360,12 @@ static void lzsa_find_all_matches(lsza_compressor *pCompressor, const int nStart
int m; int m;
for (m = 0; m < NMATCHES_PER_OFFSET; m++) { for (m = 0; m < NMATCHES_PER_OFFSET; m++) {
if (nMatches <= m || i >= (nEndOffset - 11)) { if (nMatches <= m || i > (nEndOffset - LAST_MATCH_OFFSET)) {
pMatch->length = 0; pMatch->length = 0;
pMatch->offset = 0; pMatch->offset = 0;
} }
else { else {
int nMaxLen = (nEndOffset - 5) - i; int nMaxLen = (nEndOffset - LAST_LITERALS) - i;
if (nMaxLen < 0) if (nMaxLen < 0)
nMaxLen = 0; nMaxLen = 0;
if (pMatch->length > nMaxLen) if (pMatch->length > nMaxLen)
@ -371,7 +374,6 @@ static void lzsa_find_all_matches(lsza_compressor *pCompressor, const int nStart
pMatch++; pMatch++;
} }
} }
} }
@ -619,7 +621,7 @@ static int lzsa_write_block(lsza_compressor *pCompressor, const unsigned char *p
} }
} }
if (nNumLiterals != 0) { {
int nNibbleLiteralsLen = (nNumLiterals >= LITERALS_RUN_LEN) ? LITERALS_RUN_LEN : nNumLiterals; int nNibbleLiteralsLen = (nNumLiterals >= LITERALS_RUN_LEN) ? LITERALS_RUN_LEN : nNumLiterals;
int nTokenSize = 1 /* nibble */ + lzsa_get_literals_varlen_size(nNumLiterals) + nNumLiterals; int nTokenSize = 1 /* nibble */ + lzsa_get_literals_varlen_size(nNumLiterals) + nNumLiterals;