mirror of
https://github.com/emmanuel-marty/lzsa.git
synced 2025-01-01 05:31:57 +00:00
Split non-rep from repmatch candidates
This commit is contained in:
parent
a38e8b126c
commit
0b5e915d83
@ -334,12 +334,16 @@ static void lzsa_optimize_forward_v2(lzsa_compressor *pCompressor, const unsigne
|
|||||||
int nRepOffset = arrival[(i << MATCHES_PER_ARRIVAL_SHIFT) + j].rep_offset;
|
int nRepOffset = arrival[(i << MATCHES_PER_ARRIVAL_SHIFT) + j].rep_offset;
|
||||||
int nCurMaxRepLen = 0;
|
int nCurMaxRepLen = 0;
|
||||||
|
|
||||||
if (nMatchOffset != nRepOffset &&
|
if (nRepOffset) {
|
||||||
nRepOffset &&
|
if (nMatchOffset == nRepOffset)
|
||||||
i > nRepOffset &&
|
nCurMaxRepLen = nMatchLen;
|
||||||
(i - nRepOffset + nMatchLen) <= (nEndOffset - LAST_LITERALS)) {
|
else {
|
||||||
while (nCurMaxRepLen < nMatchLen && pInWindow[i - nRepOffset + nCurMaxRepLen] == pInWindow[i - nMatchOffset + nCurMaxRepLen])
|
if (i > nRepOffset &&
|
||||||
nCurMaxRepLen++;
|
(i - nRepOffset + nMatchLen) <= (nEndOffset - LAST_LITERALS)) {
|
||||||
|
while (nCurMaxRepLen < nMatchLen && pInWindow[i - nRepOffset + nCurMaxRepLen] == pInWindow[i - nMatchOffset + nCurMaxRepLen])
|
||||||
|
nCurMaxRepLen++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nMaxRepLen[j] = nCurMaxRepLen;
|
nMaxRepLen[j] = nCurMaxRepLen;
|
||||||
@ -365,52 +369,54 @@ static void lzsa_optimize_forward_v2(lzsa_compressor *pCompressor, const unsigne
|
|||||||
|
|
||||||
if (nRepCodingChoiceCost <= pDestSlots[nMatchesPerArrival - 1].cost) {
|
if (nRepCodingChoiceCost <= pDestSlots[nMatchesPerArrival - 1].cost) {
|
||||||
int nRepOffset = arrival[(i << MATCHES_PER_ARRIVAL_SHIFT) + j].rep_offset;
|
int nRepOffset = arrival[(i << MATCHES_PER_ARRIVAL_SHIFT) + j].rep_offset;
|
||||||
int nMatchOffsetCost = (nMatchOffset == nRepOffset) ? 0 : nNoRepmatchOffsetCost;
|
|
||||||
int nCodingChoiceCost = nRepCodingChoiceCost + nMatchOffsetCost;
|
|
||||||
|
|
||||||
if (!nFavorRatio && !arrival[(i << MATCHES_PER_ARRIVAL_SHIFT) + j].num_literals)
|
if (nMatchOffset != nRepOffset) {
|
||||||
nCodingChoiceCost += MODESWITCH_PENALTY;
|
int nCodingChoiceCost = nRepCodingChoiceCost + nNoRepmatchOffsetCost;
|
||||||
|
|
||||||
if (nCodingChoiceCost <= pDestSlots[nMatchesPerArrival - 1].cost) {
|
if (!nFavorRatio && !arrival[(i << MATCHES_PER_ARRIVAL_SHIFT) + j].num_literals)
|
||||||
int exists = 0;
|
nCodingChoiceCost += MODESWITCH_PENALTY;
|
||||||
int nScore = arrival[(i << MATCHES_PER_ARRIVAL_SHIFT) + j].score + ((nMatchOffset == nRepOffset) ? 2 : 3);
|
|
||||||
|
|
||||||
for (n = 0;
|
if (nCodingChoiceCost <= pDestSlots[nMatchesPerArrival - 1].cost) {
|
||||||
n < nMatchesPerArrival && pDestSlots[n].cost <= nCodingChoiceCost;
|
int exists = 0;
|
||||||
n++) {
|
int nScore = arrival[(i << MATCHES_PER_ARRIVAL_SHIFT) + j].score + 3;
|
||||||
if (pDestSlots[n].rep_offset == nMatchOffset &&
|
|
||||||
(!nInsertForwardReps || pDestSlots[n].cost != nCodingChoiceCost || pDestSlots[n].rep_pos >= i || nScore >= (pDestSlots[n].score + nDisableScore) ||
|
|
||||||
pDestSlots[nMatchesPerArrival - 1].from_slot)) {
|
|
||||||
exists = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!exists) {
|
for (n = 0;
|
||||||
for (n = 0; n < nMatchesPerArrival; n++) {
|
n < nMatchesPerArrival && pDestSlots[n].cost <= nCodingChoiceCost;
|
||||||
lzsa_arrival *pDestArrival = &pDestSlots[n];
|
n++) {
|
||||||
|
if (pDestSlots[n].rep_offset == nMatchOffset &&
|
||||||
if (nCodingChoiceCost < pDestArrival->cost ||
|
(!nInsertForwardReps || pDestSlots[n].cost != nCodingChoiceCost || pDestSlots[n].rep_pos >= i || nScore >= (pDestSlots[n].score + nDisableScore) ||
|
||||||
(nCodingChoiceCost == pDestArrival->cost && nScore < (pDestArrival->score + nDisableScore))) {
|
pDestSlots[nMatchesPerArrival - 1].from_slot)) {
|
||||||
if (pDestArrival->from_slot) {
|
exists = 1;
|
||||||
memmove(&pDestSlots[n + 1],
|
|
||||||
&pDestSlots[n],
|
|
||||||
sizeof(lzsa_arrival) * (nMatchesPerArrival - n - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
pDestArrival->cost = nCodingChoiceCost;
|
|
||||||
pDestArrival->from_pos = i;
|
|
||||||
pDestArrival->from_slot = j + 1;
|
|
||||||
pDestArrival->match_offset = nMatchOffset;
|
|
||||||
pDestArrival->match_len = k;
|
|
||||||
pDestArrival->num_literals = 0;
|
|
||||||
pDestArrival->score = nScore;
|
|
||||||
pDestArrival->rep_offset = nMatchOffset;
|
|
||||||
pDestArrival->rep_pos = i;
|
|
||||||
pDestArrival->rep_len = k;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!exists) {
|
||||||
|
for (n = 0; n < nMatchesPerArrival; n++) {
|
||||||
|
lzsa_arrival *pDestArrival = &pDestSlots[n];
|
||||||
|
|
||||||
|
if (nCodingChoiceCost < pDestArrival->cost ||
|
||||||
|
(nCodingChoiceCost == pDestArrival->cost && nScore < (pDestArrival->score + nDisableScore))) {
|
||||||
|
if (pDestArrival->from_slot) {
|
||||||
|
memmove(&pDestSlots[n + 1],
|
||||||
|
&pDestSlots[n],
|
||||||
|
sizeof(lzsa_arrival) * (nMatchesPerArrival - n - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
pDestArrival->cost = nCodingChoiceCost;
|
||||||
|
pDestArrival->from_pos = i;
|
||||||
|
pDestArrival->from_slot = j + 1;
|
||||||
|
pDestArrival->match_offset = nMatchOffset;
|
||||||
|
pDestArrival->match_len = k;
|
||||||
|
pDestArrival->num_literals = 0;
|
||||||
|
pDestArrival->score = nScore;
|
||||||
|
pDestArrival->rep_offset = nMatchOffset;
|
||||||
|
pDestArrival->rep_pos = i;
|
||||||
|
pDestArrival->rep_len = k;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user