bzip2: move ->origPtr out of struct EState, make a few members smaller

function                                             old     new   delta
BZ2_compressBlock                                    223     228      +5
BZ2_blockSort                                         85      88      +3
generateMTFValues                                    356     357      +1
handle_compress                                      355     349      -6
compressStream                                       538     531      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/2 up/down: 9/-13)              Total: -4 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2018-02-03 20:50:20 +01:00
parent c9ae8d770b
commit 86be6d5ba9
3 changed files with 27 additions and 27 deletions

View File

@ -1022,16 +1022,15 @@ void mainSort(EState* state)
* arr1[0 .. nblock-1] holds sorted order * arr1[0 .. nblock-1] holds sorted order
*/ */
static NOINLINE static NOINLINE
void BZ2_blockSort(EState* state) int32_t BZ2_blockSort(EState* state)
{ {
/* In original bzip2 1.0.4, it's a parameter, but 30 /* In original bzip2 1.0.4, it's a parameter, but 30
* (which was the default) should work ok. */ * (which was the default) should work ok. */
enum { wfact = 30 }; enum { wfact = 30 };
unsigned i; unsigned i;
int32_t origPtr = origPtr;
if (state->nblock < 10000) { if (state->nblock >= 10000) {
fallbackSort(state);
} else {
/* Calculate the location for quadrant, remembering to get /* Calculate the location for quadrant, remembering to get
* the alignment right. Assumes that &(block[0]) is at least * the alignment right. Assumes that &(block[0]) is at least
* 2-byte aligned -- this should be ok since block is really * 2-byte aligned -- this should be ok since block is really
@ -1050,24 +1049,25 @@ void BZ2_blockSort(EState* state)
* of whether or not we use the main sort or fallback sort. * of whether or not we use the main sort or fallback sort.
*/ */
state->budget = state->nblock * ((wfact-1) / 3); state->budget = state->nblock * ((wfact-1) / 3);
mainSort(state); mainSort(state);
if (state->budget < 0) { if (state->budget >= 0)
goto good;
}
fallbackSort(state); fallbackSort(state);
} good:
}
#if BZ_LIGHT_DEBUG #if BZ_LIGHT_DEBUG
state->origPtr = -1; origPtr = -1;
#endif #endif
for (i = 0; i < state->nblock; i++) { for (i = 0; i < state->nblock; i++) {
if (state->ptr[i] == 0) { if (state->ptr[i] == 0) {
state->origPtr = i; origPtr = i;
break; break;
} }
} }
AssertH(state->origPtr != -1, 1003); AssertH(origPtr != -1, 1003);
return origPtr;
} }

View File

@ -120,9 +120,11 @@ typedef struct EState {
/* mode this stream is in, and whether inputting */ /* mode this stream is in, and whether inputting */
/* or outputting data */ /* or outputting data */
int32_t mode; uint8_t mode;
//both smallint? uint8_t state;
int32_t state;
/* misc administratium */
uint8_t blockSize100k;
/* remembers avail_in when flush/finish requested */ /* remembers avail_in when flush/finish requested */
/* bbox: not needed, strm->avail_in always has the same value */ /* bbox: not needed, strm->avail_in always has the same value */
@ -130,7 +132,6 @@ typedef struct EState {
/* uint32_t avail_in_expect; */ /* uint32_t avail_in_expect; */
/* for doing the block sorting */ /* for doing the block sorting */
int32_t origPtr;
uint32_t *arr1; uint32_t *arr1;
uint32_t *arr2; uint32_t *arr2;
uint32_t *ftab; uint32_t *ftab;
@ -144,10 +145,6 @@ typedef struct EState {
uint16_t *mtfv; uint16_t *mtfv;
uint8_t *zbits; uint8_t *zbits;
/* guess what */
uint32_t *crc32table;
//move down
/* run-length-encoding of the input */ /* run-length-encoding of the input */
uint32_t state_in_ch; uint32_t state_in_ch;
int32_t state_in_len; int32_t state_in_len;
@ -163,14 +160,15 @@ 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;
/* misc administratium */ /* misc administratium */
int32_t blockNo; int32_t blockNo;
int32_t blockSize100k;
//smallint?
/* stuff for coding the MTF values */ /* stuff for coding the MTF values */
int32_t nMTF; int32_t nMTF;
@ -206,7 +204,7 @@ typedef struct EState {
/*-- compression. --*/ /*-- compression. --*/
static void static int32_t
BZ2_blockSort(EState*); BZ2_blockSort(EState*);
static void static void

View File

@ -665,6 +665,8 @@ void sendMTFValues(EState* s)
static static
void BZ2_compressBlock(EState* s, int is_last_block) void BZ2_compressBlock(EState* s, int is_last_block)
{ {
int32_t origPtr = origPtr;
if (s->nblock > 0) { if (s->nblock > 0) {
BZ_FINALISE_CRC(s->blockCRC); BZ_FINALISE_CRC(s->blockCRC);
s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31); s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31);
@ -672,7 +674,7 @@ void BZ2_compressBlock(EState* s, int is_last_block)
if (s->blockNo > 1) if (s->blockNo > 1)
s->posZ = s->zbits; // was: s->numZ = 0; s->posZ = s->zbits; // was: s->numZ = 0;
BZ2_blockSort(s); origPtr = BZ2_blockSort(s);
} }
s->zbits = &((uint8_t*)s->arr2)[s->nblock]; s->zbits = &((uint8_t*)s->arr2)[s->nblock];
@ -713,7 +715,7 @@ void BZ2_compressBlock(EState* s, int is_last_block)
*/ */
bsW1_0(s); bsW1_0(s);
bsW(s, 24, s->origPtr); bsW(s, 24, origPtr);
generateMTFValues(s); generateMTFValues(s);
sendMTFValues(s); sendMTFValues(s);
} }