unlzma: if !LZMA_FAST, save ~200 more bytes (Pascal Bellard <pascal.bellard AT ads-lu.com>)

This commit is contained in:
Denis Vlasenko 2008-03-02 18:55:49 +00:00
parent 4aafd5f4e3
commit c3fff877e1

View File

@ -282,14 +282,16 @@ unpack_lzma_stream(int src_fd, int dst_fd)
while (global_pos + buffer_pos < header.dst_size) { while (global_pos + buffer_pos < header.dst_size) {
int pos_state = (buffer_pos + global_pos) & pos_state_mask; int pos_state = (buffer_pos + global_pos) & pos_state_mask;
prob = prob = p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;
p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;
if (rc_is_bit_0(rc, prob)) { if (rc_is_bit_0(rc, prob)) {
mi = 1; mi = 1;
rc_update_bit_0(rc, prob); rc_update_bit_0(rc, prob);
prob = (p + LZMA_LITERAL + (LZMA_LIT_SIZE prob = (p + LZMA_LITERAL
* ((((buffer_pos + global_pos) & literal_pos_mask) << lc) + (LZMA_LIT_SIZE * ((((buffer_pos + global_pos) & literal_pos_mask) << lc)
+ (previous_byte >> (8 - lc))))); + (previous_byte >> (8 - lc))
)
)
);
if (state >= LZMA_NUM_LIT_STATES) { if (state >= LZMA_NUM_LIT_STATES) {
int match_byte; int match_byte;
@ -317,8 +319,15 @@ unpack_lzma_stream(int src_fd, int dst_fd)
prob_lit = prob + mi; prob_lit = prob + mi;
rc_get_bit(rc, prob_lit, &mi); rc_get_bit(rc, prob_lit, &mi);
} }
previous_byte = (uint8_t) mi;
state -= 3;
if (state < 4-3)
state = 0;
if (state >= 10-3)
state -= 6-3;
previous_byte = (uint8_t) mi;
#if ENABLE_FEATURE_LZMA_FAST
buffer[buffer_pos++] = previous_byte; buffer[buffer_pos++] = previous_byte;
if (buffer_pos == header.dict_size) { if (buffer_pos == header.dict_size) {
buffer_pos = 0; buffer_pos = 0;
@ -327,12 +336,10 @@ unpack_lzma_stream(int src_fd, int dst_fd)
goto bad; goto bad;
USE_DESKTOP(total_written += header.dict_size;) USE_DESKTOP(total_written += header.dict_size;)
} }
if (state < 4) #else
state = 0; len = 1;
else if (state < 10) goto one_byte;
state -= 3; #endif
else
state -= 6;
} else { } else {
int offset; int offset;
uint16_t *prob_len; uint16_t *prob_len;
@ -352,11 +359,14 @@ unpack_lzma_stream(int src_fd, int dst_fd)
if (rc_is_bit_0(rc, prob)) { if (rc_is_bit_0(rc, prob)) {
rc_update_bit_0(rc, prob); rc_update_bit_0(rc, prob);
prob = (p + LZMA_IS_REP_0_LONG prob = (p + LZMA_IS_REP_0_LONG
+ (state << LZMA_NUM_POS_BITS_MAX) + pos_state); + (state << LZMA_NUM_POS_BITS_MAX)
+ pos_state
);
if (rc_is_bit_0(rc, prob)) { if (rc_is_bit_0(rc, prob)) {
rc_update_bit_0(rc, prob); rc_update_bit_0(rc, prob);
state = state < LZMA_NUM_LIT_STATES ? 9 : 11; state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
#if ENABLE_FEATURE_LZMA_FAST
pos = buffer_pos - rep0; pos = buffer_pos - rep0;
while (pos >= header.dict_size) while (pos >= header.dict_size)
pos += header.dict_size; pos += header.dict_size;
@ -370,6 +380,10 @@ unpack_lzma_stream(int src_fd, int dst_fd)
USE_DESKTOP(total_written += header.dict_size;) USE_DESKTOP(total_written += header.dict_size;)
} }
continue; continue;
#else
len = 1;
goto string;
#endif
} else { } else {
rc_update_bit_1(rc, prob); rc_update_bit_1(rc, prob);
} }
@ -405,7 +419,7 @@ unpack_lzma_stream(int src_fd, int dst_fd)
if (rc_is_bit_0(rc, prob_len)) { if (rc_is_bit_0(rc, prob_len)) {
rc_update_bit_0(rc, prob_len); rc_update_bit_0(rc, prob_len);
prob_len = (prob + LZMA_LEN_LOW prob_len = (prob + LZMA_LEN_LOW
+ (pos_state << LZMA_LEN_NUM_LOW_BITS)); + (pos_state << LZMA_LEN_NUM_LOW_BITS));
offset = 0; offset = 0;
num_bits = LZMA_LEN_NUM_LOW_BITS; num_bits = LZMA_LEN_NUM_LOW_BITS;
} else { } else {
@ -414,14 +428,14 @@ unpack_lzma_stream(int src_fd, int dst_fd)
if (rc_is_bit_0(rc, prob_len)) { if (rc_is_bit_0(rc, prob_len)) {
rc_update_bit_0(rc, prob_len); rc_update_bit_0(rc, prob_len);
prob_len = (prob + LZMA_LEN_MID prob_len = (prob + LZMA_LEN_MID
+ (pos_state << LZMA_LEN_NUM_MID_BITS)); + (pos_state << LZMA_LEN_NUM_MID_BITS));
offset = 1 << LZMA_LEN_NUM_LOW_BITS; offset = 1 << LZMA_LEN_NUM_LOW_BITS;
num_bits = LZMA_LEN_NUM_MID_BITS; num_bits = LZMA_LEN_NUM_MID_BITS;
} else { } else {
rc_update_bit_1(rc, prob_len); rc_update_bit_1(rc, prob_len);
prob_len = prob + LZMA_LEN_HIGH; prob_len = prob + LZMA_LEN_HIGH;
offset = ((1 << LZMA_LEN_NUM_LOW_BITS) offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
+ (1 << LZMA_LEN_NUM_MID_BITS)); + (1 << LZMA_LEN_NUM_MID_BITS));
num_bits = LZMA_LEN_NUM_HIGH_BITS; num_bits = LZMA_LEN_NUM_HIGH_BITS;
} }
} }
@ -432,12 +446,10 @@ unpack_lzma_stream(int src_fd, int dst_fd)
int pos_slot; int pos_slot;
state += LZMA_NUM_LIT_STATES; state += LZMA_NUM_LIT_STATES;
prob = prob = p + LZMA_POS_SLOT +
p + LZMA_POS_SLOT + ((len < LZMA_NUM_LEN_TO_POS_STATES ? len :
((len < LZMA_NUM_LEN_TO_POS_STATES - 1)
LZMA_NUM_LEN_TO_POS_STATES ? len : << LZMA_NUM_POS_SLOT_BITS);
LZMA_NUM_LEN_TO_POS_STATES - 1)
<< LZMA_NUM_POS_SLOT_BITS);
rc_bit_tree_decode(rc, prob, LZMA_NUM_POS_SLOT_BITS, rc_bit_tree_decode(rc, prob, LZMA_NUM_POS_SLOT_BITS,
&pos_slot); &pos_slot);
if (pos_slot >= LZMA_START_POS_MODEL_INDEX) { if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
@ -468,12 +480,13 @@ unpack_lzma_stream(int src_fd, int dst_fd)
} }
len += LZMA_MATCH_MIN_LEN; len += LZMA_MATCH_MIN_LEN;
SKIP_FEATURE_LZMA_FAST(string:)
do { do {
pos = buffer_pos - rep0; pos = buffer_pos - rep0;
while (pos >= header.dict_size) while (pos >= header.dict_size)
pos += header.dict_size; pos += header.dict_size;
previous_byte = buffer[pos]; previous_byte = buffer[pos];
SKIP_FEATURE_LZMA_FAST(one_byte:)
buffer[buffer_pos++] = previous_byte; buffer[buffer_pos++] = previous_byte;
if (buffer_pos == header.dict_size) { if (buffer_pos == header.dict_size) {
buffer_pos = 0; buffer_pos = 0;
@ -487,7 +500,6 @@ unpack_lzma_stream(int src_fd, int dst_fd)
} }
} }
if (full_write(dst_fd, buffer, buffer_pos) != buffer_pos) { if (full_write(dst_fd, buffer, buffer_pos) != buffer_pos) {
bad: bad:
rc_free(rc); rc_free(rc);