mirror of
https://github.com/emmanuel-marty/lzsa.git
synced 2025-01-10 20:29:32 +00:00
Reduce LZSA2 forward arrivals memory use
This commit is contained in:
parent
e4076e4090
commit
c052a188f2
@ -302,22 +302,9 @@ static void lzsa_optimize_forward_v2(lzsa_compressor *pCompressor, const int nSt
|
||||
pCompressor->best_match[i].length = 0;
|
||||
pCompressor->best_match[i].offset = 0;
|
||||
|
||||
unsigned int nRepMatchOffset = 0;
|
||||
int nEndCost = end_arrival->cost;
|
||||
|
||||
int *backward_cost = (int*)pCompressor->pos_data; /* Reuse */
|
||||
for (i = nStartOffset; i != nEndOffset; i++) {
|
||||
backward_cost[i] = nEndCost - arrival[(i << MATCHES_PER_OFFSET_SHIFT) + 0].cost;
|
||||
}
|
||||
|
||||
while (end_arrival->from_slot > 0 && end_arrival->from_pos >= 0) {
|
||||
pCompressor->best_match[end_arrival->from_pos].length = end_arrival->match_len;
|
||||
pCompressor->best_match[end_arrival->from_pos].offset = end_arrival->match_offset;
|
||||
pCompressor->repmatch_opt[end_arrival->from_pos].expected_repmatch = (end_arrival->match_len >= MIN_MATCH_SIZE_V2 && nRepMatchOffset == end_arrival->match_offset) ? 1 : 0;
|
||||
|
||||
if (end_arrival->match_len >= MIN_MATCH_SIZE_V2)
|
||||
nRepMatchOffset = end_arrival->match_offset;
|
||||
|
||||
end_arrival = &arrival[(end_arrival->from_pos << MATCHES_PER_OFFSET_SHIFT) + (end_arrival->from_slot - 1)];
|
||||
}
|
||||
}
|
||||
|
@ -92,12 +92,13 @@ int lzsa_compressor_init(lzsa_compressor *pCompressor, const int nMaxWindowSize,
|
||||
|
||||
if (pCompressor->arrival || (pCompressor->flags & LZSA_FLAG_FAVOR_RATIO) == 0) {
|
||||
if (pCompressor->format_version == 2) {
|
||||
pCompressor->selected_match = (lzsa_match *)malloc(nMaxWindowSize * NMATCHES_PER_OFFSET * sizeof(lzsa_match));
|
||||
|
||||
if (pCompressor->selected_match) {
|
||||
pCompressor->best_match = (lzsa_match *)malloc(nMaxWindowSize * sizeof(lzsa_match));
|
||||
|
||||
if (pCompressor->best_match) {
|
||||
if ((pCompressor->flags & LZSA_FLAG_FAVOR_RATIO) == 0) {
|
||||
pCompressor->selected_match = (lzsa_match *)malloc(nMaxWindowSize * NMATCHES_PER_OFFSET * sizeof(lzsa_match));
|
||||
|
||||
if (pCompressor->selected_match) {
|
||||
pCompressor->slot_cost = (int *)malloc(nMaxWindowSize * NMATCHES_PER_OFFSET * sizeof(int));
|
||||
|
||||
if (pCompressor->slot_cost) {
|
||||
@ -108,6 +109,10 @@ int lzsa_compressor_init(lzsa_compressor *pCompressor, const int nMaxWindowSize,
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user