* arr1[0 .. nblock-1] holds sorted order
*/
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
* (which was the default) should work ok. */
enum { wfact = 30 };
unsigned i;
+ int32_t origPtr = origPtr;
- if (state->nblock < 10000) {
- fallbackSort(state);
- } else {
+ if (state->nblock >= 10000) {
/* Calculate the location for quadrant, remembering to get
* the alignment right. Assumes that &(block[0]) is at least
* 2-byte aligned -- this should be ok since block is really
* of whether or not we use the main sort or fallback sort.
*/
state->budget = state->nblock * ((wfact-1) / 3);
-
mainSort(state);
- if (state->budget < 0) {
- fallbackSort(state);
- }
+ if (state->budget >= 0)
+ goto good;
}
+ fallbackSort(state);
+ good:
#if BZ_LIGHT_DEBUG
- state->origPtr = -1;
+ origPtr = -1;
#endif
for (i = 0; i < state->nblock; i++) {
if (state->ptr[i] == 0) {
- state->origPtr = i;
+ origPtr = i;
break;
}
}
- AssertH(state->origPtr != -1, 1003);
+ AssertH(origPtr != -1, 1003);
+ return origPtr;
}
/* mode this stream is in, and whether inputting */
/* or outputting data */
- int32_t mode;
-//both smallint?
- int32_t state;
+ uint8_t mode;
+ uint8_t state;
+
+ /* misc administratium */
+ uint8_t blockSize100k;
/* remembers avail_in when flush/finish requested */
/* bbox: not needed, strm->avail_in always has the same value */
/* uint32_t avail_in_expect; */
/* for doing the block sorting */
- int32_t origPtr;
uint32_t *arr1;
uint32_t *arr2;
uint32_t *ftab;
- uint16_t* quadrant;
+ uint16_t *quadrant;
int32_t budget;
/* aliases for arr1 and arr2 */
uint16_t *mtfv;
uint8_t *zbits;
- /* guess what */
- uint32_t *crc32table;
-//move down
-
/* run-length-encoding of the input */
uint32_t state_in_ch;
int32_t state_in_len;
int32_t nblock;
int32_t nblockMAX;
//int32_t numZ; // index into s->zbits[], replaced by pointer:
- uint8_t *posZ;
- uint8_t *state_out_pos;
+ uint8_t *posZ;
+ uint8_t *state_out_pos;
/* the buffer for bit stream creation */
uint32_t bsBuff;
int32_t bsLive;
+ /* guess what */
+ uint32_t *crc32table;
+
/* block and combined CRCs */
uint32_t blockCRC;
uint32_t combinedCRC;
/* misc administratium */
int32_t blockNo;
- int32_t blockSize100k;
-//smallint?
/* stuff for coding the MTF values */
int32_t nMTF;
/*-- compression. --*/
-static void
+static int32_t
BZ2_blockSort(EState*);
static void
static
void BZ2_compressBlock(EState* s, int is_last_block)
{
+ int32_t origPtr = origPtr;
+
if (s->nblock > 0) {
BZ_FINALISE_CRC(s->blockCRC);
s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31);
if (s->blockNo > 1)
s->posZ = s->zbits; // was: s->numZ = 0;
- BZ2_blockSort(s);
+ origPtr = BZ2_blockSort(s);
}
s->zbits = &((uint8_t*)s->arr2)[s->nblock];
*/
bsW1_0(s);
- bsW(s, 24, s->origPtr);
+ bsW(s, 24, origPtr);
generateMTFValues(s);
sendMTFValues(s);
}