Reduce LZSA2 forward arrivals memory use

This commit is contained in:
Emmanuel Marty 2019-09-19 11:46:03 +02:00 committed by GitHub
parent e4076e4090
commit c052a188f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 22 deletions

View File

@ -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)];
}
}

View File

@ -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;