diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-08 16:31:02 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-04-08 16:31:02 +0200 |
commit | 3d4f688a1907c80678d3f0ed4bc4fd9f99b9a63b (patch) | |
tree | cbfd7f2e7c48089994cbfd5c0e1d3e532d548928 /archival/lzop.c | |
parent | 24ef5c63750ba5330f5025f354b6d28b794fd599 (diff) | |
download | busybox-w32-3d4f688a1907c80678d3f0ed4bc4fd9f99b9a63b.tar.gz busybox-w32-3d4f688a1907c80678d3f0ed4bc4fd9f99b9a63b.tar.bz2 busybox-w32-3d4f688a1907c80678d3f0ed4bc4fd9f99b9a63b.zip |
lzop: buffer several 32-bit writes when we start a new compressed block
function old new delta
lzo_compress 483 531 +48
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r-- | archival/lzop.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/archival/lzop.c b/archival/lzop.c index f7b3bc53c..b6a3cca09 100644 --- a/archival/lzop.c +++ b/archival/lzop.c | |||
@@ -637,10 +637,8 @@ static NOINLINE int lzo_compress(const header_t *h) | |||
637 | int r = 0; /* LZO_E_OK */ | 637 | int r = 0; /* LZO_E_OK */ |
638 | uint8_t *const b1 = xzalloc(block_size); | 638 | uint8_t *const b1 = xzalloc(block_size); |
639 | uint8_t *const b2 = xzalloc(MAX_COMPRESSED_SIZE(block_size)); | 639 | uint8_t *const b2 = xzalloc(MAX_COMPRESSED_SIZE(block_size)); |
640 | unsigned src_len = 0, dst_len = 0; | ||
641 | uint32_t d_adler32 = ADLER32_INIT_VALUE; | 640 | uint32_t d_adler32 = ADLER32_INIT_VALUE; |
642 | uint32_t d_crc32 = CRC32_INIT_VALUE; | 641 | uint32_t d_crc32 = CRC32_INIT_VALUE; |
643 | int l; | ||
644 | uint8_t *wrk_mem = NULL; | 642 | uint8_t *wrk_mem = NULL; |
645 | 643 | ||
646 | if (h->method == M_LZO1X_1) | 644 | if (h->method == M_LZO1X_1) |
@@ -651,16 +649,22 @@ static NOINLINE int lzo_compress(const header_t *h) | |||
651 | wrk_mem = xzalloc(LZO1X_999_MEM_COMPRESS); | 649 | wrk_mem = xzalloc(LZO1X_999_MEM_COMPRESS); |
652 | 650 | ||
653 | for (;;) { | 651 | for (;;) { |
652 | unsigned src_len, dst_len; | ||
653 | int l; | ||
654 | uint32_t wordbuf[6]; | ||
655 | uint32_t *wordptr = wordbuf; | ||
656 | |||
654 | /* read a block */ | 657 | /* read a block */ |
655 | l = full_read(0, b1, block_size); | 658 | l = full_read(0, b1, block_size); |
656 | src_len = (l > 0 ? l : 0); | 659 | src_len = (l > 0 ? l : 0); |
657 | 660 | ||
658 | /* write uncompressed block size */ | 661 | /* write uncompressed block size */ |
659 | write32(src_len); | ||
660 | |||
661 | /* exit if last block */ | 662 | /* exit if last block */ |
662 | if (src_len == 0) | 663 | if (src_len == 0) { |
664 | write32(0); | ||
663 | break; | 665 | break; |
666 | } | ||
667 | *wordptr++ = htonl(src_len); | ||
664 | 668 | ||
665 | /* compute checksum of uncompressed block */ | 669 | /* compute checksum of uncompressed block */ |
666 | if (h->flags32 & F_ADLER32_D) | 670 | if (h->flags32 & F_ADLER32_D) |
@@ -693,30 +697,36 @@ static NOINLINE int lzo_compress(const header_t *h) | |||
693 | if (r != 0 /*LZO_E_OK*/ || new_len != src_len) | 697 | if (r != 0 /*LZO_E_OK*/ || new_len != src_len) |
694 | bb_error_msg_and_die("%s: %s", "internal error", "optimization"); | 698 | bb_error_msg_and_die("%s: %s", "internal error", "optimization"); |
695 | } | 699 | } |
696 | write32(dst_len); | 700 | *wordptr++ = htonl(dst_len); |
697 | } else { | 701 | } else { |
698 | /* data actually expanded => store data uncompressed */ | 702 | /* data actually expanded => store data uncompressed */ |
699 | write32(src_len); | 703 | *wordptr++ = htonl(src_len); |
700 | } | 704 | } |
701 | 705 | ||
702 | /* write checksum of uncompressed block */ | 706 | /* write checksum of uncompressed block */ |
703 | if (h->flags32 & F_ADLER32_D) | 707 | if (h->flags32 & F_ADLER32_D) |
704 | write32(d_adler32); | 708 | *wordptr++ = htonl(d_adler32); |
705 | if (h->flags32 & F_CRC32_D) | 709 | if (h->flags32 & F_CRC32_D) |
706 | write32(d_crc32); | 710 | *wordptr++ = htonl(d_crc32); |
707 | 711 | ||
708 | if (dst_len < src_len) { | 712 | if (dst_len < src_len) { |
709 | /* write checksum of compressed block */ | 713 | /* write checksum of compressed block */ |
710 | if (h->flags32 & F_ADLER32_C) | 714 | if (h->flags32 & F_ADLER32_C) |
711 | write32(lzo_adler32(ADLER32_INIT_VALUE, b2, dst_len)); | 715 | *wordptr++ = htonl(lzo_adler32(ADLER32_INIT_VALUE, b2, dst_len)); |
712 | if (h->flags32 & F_CRC32_C) | 716 | if (h->flags32 & F_CRC32_C) |
713 | write32(lzo_crc32(CRC32_INIT_VALUE, b2, dst_len)); | 717 | *wordptr++ = htonl(lzo_crc32(CRC32_INIT_VALUE, b2, dst_len)); |
718 | } | ||
719 | xwrite(1, wordbuf, ((char*)wordptr) - ((char*)wordbuf)); | ||
720 | if (dst_len < src_len) { | ||
714 | /* write compressed block data */ | 721 | /* write compressed block data */ |
715 | xwrite(1, b2, dst_len); | 722 | xwrite(1, b2, dst_len); |
716 | } else { | 723 | } else { |
717 | /* write uncompressed block data */ | 724 | /* write uncompressed block data */ |
718 | xwrite(1, b1, src_len); | 725 | xwrite(1, b1, src_len); |
719 | } | 726 | } |
727 | // /* if full_read() was nevertheless "short", it was EOF */ | ||
728 | // if (src_len < block_size) | ||
729 | // break; | ||
720 | } | 730 | } |
721 | 731 | ||
722 | free(wrk_mem); | 732 | free(wrk_mem); |