libbb: introduce and use common crc32 routine

function                                             old     new   delta
crc32_block_endian1                                    -      37     +37
crc32_block_endian0                                    -      34     +34
global_crc32_table                                     -       8      +8
file_read                                             82      87      +5
gzip_main                                            211     214      +3
xz_crc32                                              40      35      -5
crc32_table                                            8       -      -8
calculate_gunzip_crc                                  54      34     -20
lzo_crc32                                             54      25     -29
cksum_main                                           298     211     -87
------------------------------------------------------------------------------
(add/remove: 3/1 grow/shrink: 2/4 up/down: 87/-149)           Total: -62 bytes

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
This commit is contained in:
Denys Vlasenko
2010-10-27 15:26:45 +02:00
parent dd88ba88f5
commit 9ce642f974
9 changed files with 49 additions and 73 deletions

View File

@@ -393,7 +393,7 @@ typedef struct header_t {
} header_t;
struct globals {
const uint32_t *lzo_crc32_table;
/*const uint32_t *lzo_crc32_table;*/
chksum_t chksum_in;
chksum_t chksum_out;
} FIX_ALIASING;
@@ -468,19 +468,10 @@ lzo_adler32(uint32_t adler, const uint8_t* buf, unsigned len)
static FAST_FUNC uint32_t
lzo_crc32(uint32_t c, const uint8_t* buf, unsigned len)
{
uint32_t crc;
//if (buf == NULL) - impossible
// return 0;
if (buf == NULL)
return 0;
crc = ~c;
if (len != 0) do {
crc = G.lzo_crc32_table[(uint8_t)((int)crc ^ *buf)] ^ (crc >> 8);
buf += 1;
len -= 1;
} while (len > 0);
return ~crc;
return ~crc32_block_endian0(~c, buf, len, global_crc32_table);
}
/**********************************************************************/
@@ -679,8 +670,7 @@ static NOINLINE smallint lzo_compress(const header_t *h)
if (dst_len < src_len) {
/* write checksum of compressed block */
if (h->flags & F_ADLER32_C)
write32(lzo_adler32(ADLER32_INIT_VALUE, b2,
dst_len));
write32(lzo_adler32(ADLER32_INIT_VALUE, b2, dst_len));
if (h->flags & F_CRC32_C)
write32(lzo_crc32(CRC32_INIT_VALUE, b2, dst_len));
/* write compressed block data */
@@ -1080,6 +1070,6 @@ int lzop_main(int argc UNUSED_PARAM, char **argv)
if (applet_name[0] == 'u')
option_mask32 |= OPT_DECOMPRESS;
G.lzo_crc32_table = crc32_filltable(NULL, 0);
global_crc32_table = crc32_filltable(NULL, 0);
return bbunpack(argv, pack_lzop, make_new_name_lzop, /*unused:*/ NULL);
}