aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-03-02 18:55:49 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-03-02 18:55:49 +0000
commitc3fff877e1c7c3f2aff2833d5f5e5b7adc95ecd6 (patch)
tree1a36e1615de6d4ebacf722608bb86ecadf812853
parent4aafd5f4e30ee7f3b224652bfeaf26aa25382229 (diff)
downloadbusybox-w32-c3fff877e1c7c3f2aff2833d5f5e5b7adc95ecd6.tar.gz
busybox-w32-c3fff877e1c7c3f2aff2833d5f5e5b7adc95ecd6.tar.bz2
busybox-w32-c3fff877e1c7c3f2aff2833d5f5e5b7adc95ecd6.zip
unlzma: if !LZMA_FAST, save ~200 more bytes (Pascal Bellard <pascal.bellard AT ads-lu.com>)
-rw-r--r--archival/libunarchive/decompress_unlzma.c60
1 files changed, 36 insertions, 24 deletions
diff --git a/archival/libunarchive/decompress_unlzma.c b/archival/libunarchive/decompress_unlzma.c
index 4f36c060f..5bf4de2bd 100644
--- a/archival/libunarchive/decompress_unlzma.c
+++ b/archival/libunarchive/decompress_unlzma.c
@@ -282,14 +282,16 @@ unpack_lzma_stream(int src_fd, int dst_fd)
282 while (global_pos + buffer_pos < header.dst_size) { 282 while (global_pos + buffer_pos < header.dst_size) {
283 int pos_state = (buffer_pos + global_pos) & pos_state_mask; 283 int pos_state = (buffer_pos + global_pos) & pos_state_mask;
284 284
285 prob = 285 prob = p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;
286 p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;
287 if (rc_is_bit_0(rc, prob)) { 286 if (rc_is_bit_0(rc, prob)) {
288 mi = 1; 287 mi = 1;
289 rc_update_bit_0(rc, prob); 288 rc_update_bit_0(rc, prob);
290 prob = (p + LZMA_LITERAL + (LZMA_LIT_SIZE 289 prob = (p + LZMA_LITERAL
291 * ((((buffer_pos + global_pos) & literal_pos_mask) << lc) 290 + (LZMA_LIT_SIZE * ((((buffer_pos + global_pos) & literal_pos_mask) << lc)
292 + (previous_byte >> (8 - lc))))); 291 + (previous_byte >> (8 - lc))
292 )
293 )
294 );
293 295
294 if (state >= LZMA_NUM_LIT_STATES) { 296 if (state >= LZMA_NUM_LIT_STATES) {
295 int match_byte; 297 int match_byte;
@@ -317,8 +319,15 @@ unpack_lzma_stream(int src_fd, int dst_fd)
317 prob_lit = prob + mi; 319 prob_lit = prob + mi;
318 rc_get_bit(rc, prob_lit, &mi); 320 rc_get_bit(rc, prob_lit, &mi);
319 } 321 }
320 previous_byte = (uint8_t) mi;
321 322
323 state -= 3;
324 if (state < 4-3)
325 state = 0;
326 if (state >= 10-3)
327 state -= 6-3;
328
329 previous_byte = (uint8_t) mi;
330#if ENABLE_FEATURE_LZMA_FAST
322 buffer[buffer_pos++] = previous_byte; 331 buffer[buffer_pos++] = previous_byte;
323 if (buffer_pos == header.dict_size) { 332 if (buffer_pos == header.dict_size) {
324 buffer_pos = 0; 333 buffer_pos = 0;
@@ -327,12 +336,10 @@ unpack_lzma_stream(int src_fd, int dst_fd)
327 goto bad; 336 goto bad;
328 USE_DESKTOP(total_written += header.dict_size;) 337 USE_DESKTOP(total_written += header.dict_size;)
329 } 338 }
330 if (state < 4) 339#else
331 state = 0; 340 len = 1;
332 else if (state < 10) 341 goto one_byte;
333 state -= 3; 342#endif
334 else
335 state -= 6;
336 } else { 343 } else {
337 int offset; 344 int offset;
338 uint16_t *prob_len; 345 uint16_t *prob_len;
@@ -352,11 +359,14 @@ unpack_lzma_stream(int src_fd, int dst_fd)
352 if (rc_is_bit_0(rc, prob)) { 359 if (rc_is_bit_0(rc, prob)) {
353 rc_update_bit_0(rc, prob); 360 rc_update_bit_0(rc, prob);
354 prob = (p + LZMA_IS_REP_0_LONG 361 prob = (p + LZMA_IS_REP_0_LONG
355 + (state << LZMA_NUM_POS_BITS_MAX) + pos_state); 362 + (state << LZMA_NUM_POS_BITS_MAX)
363 + pos_state
364 );
356 if (rc_is_bit_0(rc, prob)) { 365 if (rc_is_bit_0(rc, prob)) {
357 rc_update_bit_0(rc, prob); 366 rc_update_bit_0(rc, prob);
358 367
359 state = state < LZMA_NUM_LIT_STATES ? 9 : 11; 368 state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
369#if ENABLE_FEATURE_LZMA_FAST
360 pos = buffer_pos - rep0; 370 pos = buffer_pos - rep0;
361 while (pos >= header.dict_size) 371 while (pos >= header.dict_size)
362 pos += header.dict_size; 372 pos += header.dict_size;
@@ -370,6 +380,10 @@ unpack_lzma_stream(int src_fd, int dst_fd)
370 USE_DESKTOP(total_written += header.dict_size;) 380 USE_DESKTOP(total_written += header.dict_size;)
371 } 381 }
372 continue; 382 continue;
383#else
384 len = 1;
385 goto string;
386#endif
373 } else { 387 } else {
374 rc_update_bit_1(rc, prob); 388 rc_update_bit_1(rc, prob);
375 } 389 }
@@ -405,7 +419,7 @@ unpack_lzma_stream(int src_fd, int dst_fd)
405 if (rc_is_bit_0(rc, prob_len)) { 419 if (rc_is_bit_0(rc, prob_len)) {
406 rc_update_bit_0(rc, prob_len); 420 rc_update_bit_0(rc, prob_len);
407 prob_len = (prob + LZMA_LEN_LOW 421 prob_len = (prob + LZMA_LEN_LOW
408 + (pos_state << LZMA_LEN_NUM_LOW_BITS)); 422 + (pos_state << LZMA_LEN_NUM_LOW_BITS));
409 offset = 0; 423 offset = 0;
410 num_bits = LZMA_LEN_NUM_LOW_BITS; 424 num_bits = LZMA_LEN_NUM_LOW_BITS;
411 } else { 425 } else {
@@ -414,14 +428,14 @@ unpack_lzma_stream(int src_fd, int dst_fd)
414 if (rc_is_bit_0(rc, prob_len)) { 428 if (rc_is_bit_0(rc, prob_len)) {
415 rc_update_bit_0(rc, prob_len); 429 rc_update_bit_0(rc, prob_len);
416 prob_len = (prob + LZMA_LEN_MID 430 prob_len = (prob + LZMA_LEN_MID
417 + (pos_state << LZMA_LEN_NUM_MID_BITS)); 431 + (pos_state << LZMA_LEN_NUM_MID_BITS));
418 offset = 1 << LZMA_LEN_NUM_LOW_BITS; 432 offset = 1 << LZMA_LEN_NUM_LOW_BITS;
419 num_bits = LZMA_LEN_NUM_MID_BITS; 433 num_bits = LZMA_LEN_NUM_MID_BITS;
420 } else { 434 } else {
421 rc_update_bit_1(rc, prob_len); 435 rc_update_bit_1(rc, prob_len);
422 prob_len = prob + LZMA_LEN_HIGH; 436 prob_len = prob + LZMA_LEN_HIGH;
423 offset = ((1 << LZMA_LEN_NUM_LOW_BITS) 437 offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
424 + (1 << LZMA_LEN_NUM_MID_BITS)); 438 + (1 << LZMA_LEN_NUM_MID_BITS));
425 num_bits = LZMA_LEN_NUM_HIGH_BITS; 439 num_bits = LZMA_LEN_NUM_HIGH_BITS;
426 } 440 }
427 } 441 }
@@ -432,12 +446,10 @@ unpack_lzma_stream(int src_fd, int dst_fd)
432 int pos_slot; 446 int pos_slot;
433 447
434 state += LZMA_NUM_LIT_STATES; 448 state += LZMA_NUM_LIT_STATES;
435 prob = 449 prob = p + LZMA_POS_SLOT +
436 p + LZMA_POS_SLOT + 450 ((len < LZMA_NUM_LEN_TO_POS_STATES ? len :
437 ((len < 451 LZMA_NUM_LEN_TO_POS_STATES - 1)
438 LZMA_NUM_LEN_TO_POS_STATES ? len : 452 << LZMA_NUM_POS_SLOT_BITS);
439 LZMA_NUM_LEN_TO_POS_STATES - 1)
440 << LZMA_NUM_POS_SLOT_BITS);
441 rc_bit_tree_decode(rc, prob, LZMA_NUM_POS_SLOT_BITS, 453 rc_bit_tree_decode(rc, prob, LZMA_NUM_POS_SLOT_BITS,
442 &pos_slot); 454 &pos_slot);
443 if (pos_slot >= LZMA_START_POS_MODEL_INDEX) { 455 if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
@@ -468,12 +480,13 @@ unpack_lzma_stream(int src_fd, int dst_fd)
468 } 480 }
469 481
470 len += LZMA_MATCH_MIN_LEN; 482 len += LZMA_MATCH_MIN_LEN;
471 483 SKIP_FEATURE_LZMA_FAST(string:)
472 do { 484 do {
473 pos = buffer_pos - rep0; 485 pos = buffer_pos - rep0;
474 while (pos >= header.dict_size) 486 while (pos >= header.dict_size)
475 pos += header.dict_size; 487 pos += header.dict_size;
476 previous_byte = buffer[pos]; 488 previous_byte = buffer[pos];
489 SKIP_FEATURE_LZMA_FAST(one_byte:)
477 buffer[buffer_pos++] = previous_byte; 490 buffer[buffer_pos++] = previous_byte;
478 if (buffer_pos == header.dict_size) { 491 if (buffer_pos == header.dict_size) {
479 buffer_pos = 0; 492 buffer_pos = 0;
@@ -487,7 +500,6 @@ unpack_lzma_stream(int src_fd, int dst_fd)
487 } 500 }
488 } 501 }
489 502
490
491 if (full_write(dst_fd, buffer, buffer_pos) != buffer_pos) { 503 if (full_write(dst_fd, buffer, buffer_pos) != buffer_pos) {
492 bad: 504 bad:
493 rc_free(rc); 505 rc_free(rc);