mirror of
https://github.com/emmanuel-marty/lzsa.git
synced 2024-06-03 06:29:27 +00:00
Compress LZSA2 a bit faster again; small cleanup
This commit is contained in:
parent
9e11c0893a
commit
34de880080
|
@ -195,14 +195,13 @@ static void lzsa_optimize_forward_v1(lzsa_compressor *pCompressor, lzsa_match *p
|
||||||
}
|
}
|
||||||
|
|
||||||
for (n = 0; n < NARRIVALS_PER_POSITION_V1 /* we only need the literals + short match cost + long match cost cases */; n++) {
|
for (n = 0; n < NARRIVALS_PER_POSITION_V1 /* we only need the literals + short match cost + long match cost cases */; n++) {
|
||||||
lzsa_arrival *pDestArrival = &pDestLiteralSlots[n];
|
if (nCodingChoiceCost < pDestLiteralSlots[n].cost ||
|
||||||
|
(nCodingChoiceCost == pDestLiteralSlots[n].cost && nScore < (pDestLiteralSlots[n].score + nDisableScore))) {
|
||||||
if (nCodingChoiceCost < pDestArrival->cost ||
|
|
||||||
(nCodingChoiceCost == pDestArrival->cost && nScore < (pDestArrival->score + nDisableScore))) {
|
|
||||||
memmove(&pDestLiteralSlots[n + 1],
|
memmove(&pDestLiteralSlots[n + 1],
|
||||||
&pDestLiteralSlots[n],
|
&pDestLiteralSlots[n],
|
||||||
sizeof(lzsa_arrival) * (NARRIVALS_PER_POSITION_V1 - n - 1));
|
sizeof(lzsa_arrival) * (NARRIVALS_PER_POSITION_V1 - n - 1));
|
||||||
|
|
||||||
|
lzsa_arrival* pDestArrival = &pDestLiteralSlots[n];
|
||||||
pDestArrival->cost = nCodingChoiceCost;
|
pDestArrival->cost = nCodingChoiceCost;
|
||||||
pDestArrival->rep_offset = cur_arrival[j].rep_offset;
|
pDestArrival->rep_offset = cur_arrival[j].rep_offset;
|
||||||
pDestArrival->from_slot = j + 1;
|
pDestArrival->from_slot = j + 1;
|
||||||
|
@ -256,22 +255,19 @@ static void lzsa_optimize_forward_v1(lzsa_compressor *pCompressor, lzsa_match *p
|
||||||
int nNonRepMatchIdx = -1;
|
int nNonRepMatchIdx = -1;
|
||||||
|
|
||||||
for (n = 0; n < NARRIVALS_PER_POSITION_V1 /* we only need the literals + short match cost + long match cost cases */; n++) {
|
for (n = 0; n < NARRIVALS_PER_POSITION_V1 /* we only need the literals + short match cost + long match cost cases */; n++) {
|
||||||
lzsa_arrival* pDestArrival = &pDestSlots[n];
|
if (nCodingChoiceCost < pDestSlots[n].cost ||
|
||||||
|
(nCodingChoiceCost == pDestSlots[n].cost && nScore < (pDestSlots[n].score + nDisableScore))) {
|
||||||
if (nCodingChoiceCost < pDestArrival->cost ||
|
|
||||||
(nCodingChoiceCost == pDestArrival->cost && nScore < (pDestArrival->score + nDisableScore))) {
|
|
||||||
nNonRepMatchIdx = n;
|
nNonRepMatchIdx = n;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nNonRepMatchIdx >= 0) {
|
if (nNonRepMatchIdx >= 0) {
|
||||||
lzsa_arrival* pDestArrival = &pDestSlots[nNonRepMatchIdx];
|
|
||||||
|
|
||||||
memmove(&pDestSlots[nNonRepMatchIdx + 1],
|
memmove(&pDestSlots[nNonRepMatchIdx + 1],
|
||||||
&pDestSlots[nNonRepMatchIdx],
|
&pDestSlots[nNonRepMatchIdx],
|
||||||
sizeof(lzsa_arrival) * (NARRIVALS_PER_POSITION_V1 - nNonRepMatchIdx - 1));
|
sizeof(lzsa_arrival) * (NARRIVALS_PER_POSITION_V1 - nNonRepMatchIdx - 1));
|
||||||
|
|
||||||
|
lzsa_arrival* pDestArrival = &pDestSlots[nNonRepMatchIdx];
|
||||||
pDestArrival->cost = nCodingChoiceCost;
|
pDestArrival->cost = nCodingChoiceCost;
|
||||||
pDestArrival->rep_offset = match[m].offset;
|
pDestArrival->rep_offset = match[m].offset;
|
||||||
pDestArrival->from_slot = j + 1;
|
pDestArrival->from_slot = j + 1;
|
||||||
|
@ -292,8 +288,7 @@ static void lzsa_optimize_forward_v1(lzsa_compressor *pCompressor, lzsa_match *p
|
||||||
|
|
||||||
const lzsa_arrival *end_arrival = &arrival[(i << ARRIVALS_PER_POSITION_SHIFT) + 0];
|
const lzsa_arrival *end_arrival = &arrival[(i << ARRIVALS_PER_POSITION_SHIFT) + 0];
|
||||||
|
|
||||||
while (end_arrival->from_slot > 0 && end_arrival->from_pos >= 0) {
|
while (end_arrival->from_slot > 0 && end_arrival->from_pos >= 0 && end_arrival->from_pos < nEndOffset) {
|
||||||
if (end_arrival->from_pos >= nEndOffset) return;
|
|
||||||
pBestMatch[end_arrival->from_pos].length = end_arrival->match_len;
|
pBestMatch[end_arrival->from_pos].length = end_arrival->match_len;
|
||||||
if (end_arrival->match_len)
|
if (end_arrival->match_len)
|
||||||
pBestMatch[end_arrival->from_pos].offset = end_arrival->rep_offset;
|
pBestMatch[end_arrival->from_pos].offset = end_arrival->rep_offset;
|
||||||
|
|
|
@ -218,12 +218,12 @@ static void lzsa_insert_forward_match_v2(lzsa_compressor *pCompressor, const uns
|
||||||
const unsigned char* pInWindowStart = pInWindow + nRepPos;
|
const unsigned char* pInWindowStart = pInWindow + nRepPos;
|
||||||
|
|
||||||
if (!memcmp(pInWindowStart, pInWindowStart - nMatchOffset, 2)) {
|
if (!memcmp(pInWindowStart, pInWindowStart - nMatchOffset, 2)) {
|
||||||
if (nRepLen >= MIN_MATCH_SIZE_V2) {
|
const int nLen0 = rle_len[nRepPos - nMatchOffset];
|
||||||
const int nLen0 = rle_len[nRepPos - nMatchOffset];
|
const int nLen1 = rle_len[nRepPos];
|
||||||
const int nLen1 = rle_len[nRepPos];
|
const int nMinLen = (nLen0 < nLen1) ? nLen0 : nLen1;
|
||||||
const int nMinLen = (nLen0 < nLen1) ? nLen0 : nLen1;
|
|
||||||
|
|
||||||
if (nMinLen >= nRepLen || !memcmp(pInWindowStart + nMinLen, pInWindowStart + nMinLen - nMatchOffset, nRepLen - nMinLen)) {
|
if (nMinLen >= nRepLen || !memcmp(pInWindowStart + nMinLen, pInWindowStart + nMinLen - nMatchOffset, nRepLen - nMinLen)) {
|
||||||
|
if (nRepLen >= MIN_MATCH_SIZE_V2) {
|
||||||
if (nRepOffset) {
|
if (nRepOffset) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
@ -261,9 +261,9 @@ static void lzsa_insert_forward_match_v2(lzsa_compressor *pCompressor, const uns
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
visited[nRepPos].length = nRepLen;
|
else {
|
||||||
}
|
visited[nRepPos].length = nRepLen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user