mirror of
https://github.com/emmanuel-marty/lzsa.git
synced 2025-01-03 19:30:35 +00:00
Compress LZSA2 a tiny bit faster
This commit is contained in:
parent
1d0427ecae
commit
b88d3465e3
@ -187,21 +187,28 @@ static inline int lzsa_write_match_varlen_v2(unsigned char *pOutData, int nOutOf
|
|||||||
* @param nDepth current insertion depth
|
* @param nDepth current insertion depth
|
||||||
*/
|
*/
|
||||||
static void lzsa_insert_forward_match_v2(lzsa_compressor *pCompressor, const unsigned char *pInWindow, const int i, const int nMatchOffset, const int nStartOffset, const int nEndOffset, const int nMatchesPerArrival, int nDepth) {
|
static void lzsa_insert_forward_match_v2(lzsa_compressor *pCompressor, const unsigned char *pInWindow, const int i, const int nMatchOffset, const int nStartOffset, const int nEndOffset, const int nMatchesPerArrival, int nDepth) {
|
||||||
lzsa_arrival *arrival = pCompressor->arrival - (nStartOffset << MATCHES_PER_ARRIVAL_SHIFT);
|
lzsa_arrival *arrival = pCompressor->arrival + ((i - nStartOffset) << MATCHES_PER_ARRIVAL_SHIFT);
|
||||||
int j;
|
int j;
|
||||||
|
int nPrevRepPos = -1, nPrevRepLen = -1, nPrevPrevRepPos = -1, nPrevPrevRepLen = -1;
|
||||||
|
|
||||||
if (nDepth >= 10) return;
|
for (j = 0; j < nMatchesPerArrival && arrival[j].from_slot; j++) {
|
||||||
|
int nRepOffset = arrival[j].rep_offset;
|
||||||
|
|
||||||
for (j = 0; j < nMatchesPerArrival && arrival[(i << MATCHES_PER_ARRIVAL_SHIFT) + j].from_slot; j++) {
|
if (nMatchOffset != nRepOffset && nRepOffset && arrival[j].rep_len >= MIN_MATCH_SIZE_V2) {
|
||||||
int nRepOffset = arrival[(i << MATCHES_PER_ARRIVAL_SHIFT) + j].rep_offset;
|
int nRepPos = arrival[j].rep_pos;
|
||||||
|
int nRepLen = arrival[j].rep_len;
|
||||||
if (nMatchOffset != nRepOffset && nRepOffset && arrival[(i << MATCHES_PER_ARRIVAL_SHIFT) + j].rep_len >= MIN_MATCH_SIZE_V2) {
|
|
||||||
int nRepPos = arrival[(i << MATCHES_PER_ARRIVAL_SHIFT) + j].rep_pos;
|
|
||||||
int nRepLen = arrival[(i << MATCHES_PER_ARRIVAL_SHIFT) + j].rep_len;
|
|
||||||
|
|
||||||
if (nRepPos > nMatchOffset &&
|
if (nRepPos > nMatchOffset &&
|
||||||
(nRepPos - nMatchOffset + nRepLen) <= (nEndOffset - LAST_LITERALS) &&
|
(nRepPos - nMatchOffset + nRepLen) <= (nEndOffset - LAST_LITERALS) &&
|
||||||
!memcmp(pInWindow + nRepPos - nRepOffset, pInWindow + nRepPos - nMatchOffset, nRepLen)) {
|
pCompressor->match[((nRepPos - nStartOffset) << MATCHES_PER_INDEX_SHIFT_V2) + NMATCHES_PER_INDEX_V2 - 1].length == 0) {
|
||||||
|
|
||||||
|
if ((nPrevRepPos != nRepPos || nPrevRepLen != nRepLen) && (nPrevPrevRepPos != nRepPos || nPrevPrevRepLen != nRepLen)) {
|
||||||
|
nPrevPrevRepPos = nPrevRepPos;
|
||||||
|
nPrevPrevRepLen = nPrevRepLen;
|
||||||
|
nPrevRepPos = nRepPos;
|
||||||
|
nPrevRepLen = nRepLen;
|
||||||
|
|
||||||
|
if (!memcmp(pInWindow + nRepPos, pInWindow + nRepPos - nMatchOffset, nRepLen)) {
|
||||||
int nCurRepLen = nRepLen;
|
int nCurRepLen = nRepLen;
|
||||||
|
|
||||||
int nMaxRepLen = nEndOffset - nRepPos;
|
int nMaxRepLen = nEndOffset - nRepPos;
|
||||||
@ -214,31 +221,31 @@ static void lzsa_insert_forward_match_v2(lzsa_compressor *pCompressor, const uns
|
|||||||
while (nCurRepLen < nMaxRepLen && pInWindow[nRepPos + nCurRepLen] == pInWindow[nRepPos - nMatchOffset + nCurRepLen])
|
while (nCurRepLen < nMaxRepLen && pInWindow[nRepPos + nCurRepLen] == pInWindow[nRepPos - nMatchOffset + nCurRepLen])
|
||||||
nCurRepLen++;
|
nCurRepLen++;
|
||||||
|
|
||||||
lzsa_match *fwd_match = pCompressor->match + ((nRepPos - nStartOffset) << MATCHES_PER_INDEX_SHIFT_V2);
|
lzsa_match* fwd_match = pCompressor->match + ((nRepPos - nStartOffset) << MATCHES_PER_INDEX_SHIFT_V2);
|
||||||
int exists = 0;
|
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
for (r = 0; r < NMATCHES_PER_INDEX_V2 && fwd_match[r].length >= MIN_MATCH_SIZE_V2; r++) {
|
for (r = 0; r < NMATCHES_PER_INDEX_V2 && fwd_match[r].length >= MIN_MATCH_SIZE_V2; r++) {
|
||||||
if (fwd_match[r].offset == nMatchOffset) {
|
if (fwd_match[r].offset == nMatchOffset) {
|
||||||
exists = 1;
|
if (fwd_match[r].length < nCurRepLen)
|
||||||
|
|
||||||
if (fwd_match[r].length < nCurRepLen) {
|
|
||||||
fwd_match[r].length = nCurRepLen;
|
fwd_match[r].length = nCurRepLen;
|
||||||
lzsa_insert_forward_match_v2(pCompressor, pInWindow, nRepPos, nMatchOffset, nStartOffset, nEndOffset, nMatchesPerArrival, nDepth + 1);
|
|
||||||
}
|
r = NMATCHES_PER_INDEX_V2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!exists && r < NMATCHES_PER_INDEX_V2) {
|
if (r < NMATCHES_PER_INDEX_V2) {
|
||||||
fwd_match[r].offset = nMatchOffset;
|
fwd_match[r].offset = nMatchOffset;
|
||||||
fwd_match[r].length = nCurRepLen;
|
fwd_match[r].length = nCurRepLen;
|
||||||
|
|
||||||
|
if (nDepth < 9)
|
||||||
lzsa_insert_forward_match_v2(pCompressor, pInWindow, nRepPos, nMatchOffset, nStartOffset, nEndOffset, nMatchesPerArrival, nDepth + 1);
|
lzsa_insert_forward_match_v2(pCompressor, pInWindow, nRepPos, nMatchOffset, nStartOffset, nEndOffset, nMatchesPerArrival, nDepth + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user