bzip: make ftab[] and crc32table[] member arrays of EState, do not allocate

function                                             old     new   delta
mainSort                                             941     986     +45
fallbackSort                                        1471    1469      -2
add_pair_to_block                                    194     188      -6
compressStream                                       543     515     -28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/3 up/down: 45/-36)              Total: 9 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2021-08-29 15:32:42 +02:00
parent 49a2e484b5
commit 6d3da732a5
2 changed files with 10 additions and 8 deletions

View File

@ -99,9 +99,8 @@ void BZ2_bzCompressInit(bz_stream *strm, int blockSize100k)
s->ptr = (uint32_t*)s->arr1; s->ptr = (uint32_t*)s->arr1;
s->arr2 = xmalloc((n + BZ_N_OVERSHOOT) * sizeof(uint32_t)); s->arr2 = xmalloc((n + BZ_N_OVERSHOOT) * sizeof(uint32_t));
s->block = (uint8_t*)s->arr2; s->block = (uint8_t*)s->arr2;
s->ftab = xmalloc(65537 * sizeof(uint32_t));
s->crc32table = crc32_filltable(NULL, 1); crc32_filltable(s->crc32table, 1);
s->state = BZ_S_INPUT; s->state = BZ_S_INPUT;
s->mode = BZ_M_RUNNING; s->mode = BZ_M_RUNNING;
@ -369,8 +368,8 @@ void BZ2_bzCompressEnd(bz_stream *strm)
s = strm->state; s = strm->state;
free(s->arr1); free(s->arr1);
free(s->arr2); free(s->arr2);
free(s->ftab); //free(s->ftab); // made it array member of s
free(s->crc32table); //free(s->crc32table); // ditto
free(s); free(s);
} }

View File

@ -134,7 +134,7 @@ typedef struct EState {
/* for doing the block sorting */ /* for doing the block sorting */
uint32_t *arr1; uint32_t *arr1;
uint32_t *arr2; uint32_t *arr2;
uint32_t *ftab; //uint32_t *ftab; //moved into this struct, see below
uint16_t *quadrant; uint16_t *quadrant;
int32_t budget; int32_t budget;
@ -160,9 +160,6 @@ typedef struct EState {
uint32_t bsBuff; uint32_t bsBuff;
int32_t bsLive; int32_t bsLive;
/* guess what */
uint32_t *crc32table;
/* block and combined CRCs */ /* block and combined CRCs */
uint32_t blockCRC; uint32_t blockCRC;
uint32_t combinedCRC; uint32_t combinedCRC;
@ -185,6 +182,12 @@ typedef struct EState {
uint8_t len[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; uint8_t len[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
/* guess what */
uint32_t crc32table[256];
/* for doing the block sorting */
uint32_t ftab[65537];
/* stack-saving measures: these can be local, but they are too big */ /* stack-saving measures: these can be local, but they are too big */
int32_t sendMTFValues__code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; int32_t sendMTFValues__code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
int32_t sendMTFValues__rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; int32_t sendMTFValues__rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];