diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-02-01 10:56:19 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-02-01 10:56:19 +0100 |
commit | ddacb03e875dd4c1a79421d030da9cdc4f081e6e (patch) | |
tree | 5fef3dda6eb881153d8acef87a297fc75223398e | |
parent | 06076494da41755893a6e072bbd9889581a9e9d1 (diff) | |
download | busybox-w32-ddacb03e875dd4c1a79421d030da9cdc4f081e6e.tar.gz busybox-w32-ddacb03e875dd4c1a79421d030da9cdc4f081e6e.tar.bz2 busybox-w32-ddacb03e875dd4c1a79421d030da9cdc4f081e6e.zip |
libbb: commonalize a bit of little-endian CRC32 table generation code
function old new delta
global_crc32_new_table_le - 11 +11
crc32_new_table_le - 9 +9
inflate_unzip_internal 560 556 -4
flash_eraseall_main 823 819 -4
unpack_xz_stream 2403 2394 -9
lzop_main 121 112 -9
gzip_main 187 178 -9
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/5 up/down: 20/-35) Total: -15 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/gzip.c | 2 | ||||
-rw-r--r-- | archival/libarchive/decompress_gunzip.c | 2 | ||||
-rw-r--r-- | archival/libarchive/decompress_unxz.c | 2 | ||||
-rw-r--r-- | archival/lzop.c | 2 | ||||
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | libbb/crc32.c | 10 | ||||
-rw-r--r-- | miscutils/flash_eraseall.c | 2 | ||||
-rw-r--r-- | util-linux/fdisk_gpt.c | 2 |
8 files changed, 18 insertions, 6 deletions
diff --git a/archival/gzip.c b/archival/gzip.c index e3dd79291..c5a1fe9b4 100644 --- a/archival/gzip.c +++ b/archival/gzip.c | |||
@@ -2239,7 +2239,7 @@ int gzip_main(int argc UNUSED_PARAM, char **argv) | |||
2239 | ALLOC(ush, G1.prev, 1L << BITS); | 2239 | ALLOC(ush, G1.prev, 1L << BITS); |
2240 | 2240 | ||
2241 | /* Initialize the CRC32 table */ | 2241 | /* Initialize the CRC32 table */ |
2242 | global_crc32_table = crc32_filltable(NULL, 0); | 2242 | global_crc32_new_table_le(); |
2243 | 2243 | ||
2244 | argv += optind; | 2244 | argv += optind; |
2245 | return bbunpack(argv, pack_gzip, append_ext, "gz"); | 2245 | return bbunpack(argv, pack_gzip, append_ext, "gz"); |
diff --git a/archival/libarchive/decompress_gunzip.c b/archival/libarchive/decompress_gunzip.c index c8245d736..edff7e0e5 100644 --- a/archival/libarchive/decompress_gunzip.c +++ b/archival/libarchive/decompress_gunzip.c | |||
@@ -1000,7 +1000,7 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate) | |||
1000 | gunzip_bb = 0; | 1000 | gunzip_bb = 0; |
1001 | 1001 | ||
1002 | /* Create the crc table */ | 1002 | /* Create the crc table */ |
1003 | gunzip_crc_table = crc32_filltable(NULL, 0); | 1003 | gunzip_crc_table = crc32_new_table_le(); |
1004 | gunzip_crc = ~0; | 1004 | gunzip_crc = ~0; |
1005 | 1005 | ||
1006 | error_msg = "corrupted data"; | 1006 | error_msg = "corrupted data"; |
diff --git a/archival/libarchive/decompress_unxz.c b/archival/libarchive/decompress_unxz.c index 0be85500c..8ae7a275b 100644 --- a/archival/libarchive/decompress_unxz.c +++ b/archival/libarchive/decompress_unxz.c | |||
@@ -52,7 +52,7 @@ unpack_xz_stream(transformer_state_t *xstate) | |||
52 | IF_DESKTOP(long long) int total = 0; | 52 | IF_DESKTOP(long long) int total = 0; |
53 | 53 | ||
54 | if (!global_crc32_table) | 54 | if (!global_crc32_table) |
55 | global_crc32_table = crc32_filltable(NULL, /*endian:*/ 0); | 55 | global_crc32_new_table_le(); |
56 | 56 | ||
57 | memset(&iobuf, 0, sizeof(iobuf)); | 57 | memset(&iobuf, 0, sizeof(iobuf)); |
58 | membuf = xmalloc(2 * BUFSIZ); | 58 | membuf = xmalloc(2 * BUFSIZ); |
diff --git a/archival/lzop.c b/archival/lzop.c index ba27aeff0..fef8cdba3 100644 --- a/archival/lzop.c +++ b/archival/lzop.c | |||
@@ -1148,6 +1148,6 @@ int lzop_main(int argc UNUSED_PARAM, char **argv) | |||
1148 | if (ENABLE_UNLZOP && applet_name[4] == 'o') | 1148 | if (ENABLE_UNLZOP && applet_name[4] == 'o') |
1149 | option_mask32 |= OPT_DECOMPRESS; | 1149 | option_mask32 |= OPT_DECOMPRESS; |
1150 | 1150 | ||
1151 | global_crc32_table = crc32_filltable(NULL, 0); | 1151 | global_crc32_new_table_le(); |
1152 | return bbunpack(argv, pack_lzop, make_new_name_lzop, /*unused:*/ NULL); | 1152 | return bbunpack(argv, pack_lzop, make_new_name_lzop, /*unused:*/ NULL); |
1153 | } | 1153 | } |
diff --git a/include/libbb.h b/include/libbb.h index a93864020..2bb364366 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1928,6 +1928,8 @@ typedef struct md5_ctx_t md5sha_ctx_t; | |||
1928 | 1928 | ||
1929 | extern uint32_t *global_crc32_table; | 1929 | extern uint32_t *global_crc32_table; |
1930 | uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; | 1930 | uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; |
1931 | uint32_t *crc32_new_table_le(void) FAST_FUNC; | ||
1932 | uint32_t *global_crc32_new_table_le(void) FAST_FUNC; | ||
1931 | uint32_t crc32_block_endian1(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) FAST_FUNC; | 1933 | uint32_t crc32_block_endian1(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) FAST_FUNC; |
1932 | uint32_t crc32_block_endian0(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) FAST_FUNC; | 1934 | uint32_t crc32_block_endian0(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) FAST_FUNC; |
1933 | 1935 | ||
diff --git a/libbb/crc32.c b/libbb/crc32.c index b00b580d0..728bcb736 100644 --- a/libbb/crc32.c +++ b/libbb/crc32.c | |||
@@ -41,6 +41,16 @@ uint32_t* FAST_FUNC crc32_filltable(uint32_t *crc_table, int endian) | |||
41 | 41 | ||
42 | return crc_table - 256; | 42 | return crc_table - 256; |
43 | } | 43 | } |
44 | /* Common uses: */ | ||
45 | uint32_t* FAST_FUNC crc32_new_table_le(void) | ||
46 | { | ||
47 | return crc32_filltable(NULL, 0); | ||
48 | } | ||
49 | uint32_t* FAST_FUNC global_crc32_new_table_le(void) | ||
50 | { | ||
51 | global_crc32_table = crc32_new_table_le(); | ||
52 | return global_crc32_table; | ||
53 | } | ||
44 | 54 | ||
45 | uint32_t FAST_FUNC crc32_block_endian1(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) | 55 | uint32_t FAST_FUNC crc32_block_endian1(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) |
46 | { | 56 | { |
diff --git a/miscutils/flash_eraseall.c b/miscutils/flash_eraseall.c index fab21291c..8e93060ca 100644 --- a/miscutils/flash_eraseall.c +++ b/miscutils/flash_eraseall.c | |||
@@ -101,7 +101,7 @@ int flash_eraseall_main(int argc UNUSED_PARAM, char **argv) | |||
101 | if (flags & OPTION_J) { | 101 | if (flags & OPTION_J) { |
102 | uint32_t *crc32_table; | 102 | uint32_t *crc32_table; |
103 | 103 | ||
104 | crc32_table = crc32_filltable(NULL, 0); | 104 | crc32_table = crc32_new_table_le(); |
105 | 105 | ||
106 | cleanmarker.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); | 106 | cleanmarker.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); |
107 | cleanmarker.nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER); | 107 | cleanmarker.nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER); |
diff --git a/util-linux/fdisk_gpt.c b/util-linux/fdisk_gpt.c index 45d2aa6e7..cdb90627d 100644 --- a/util-linux/fdisk_gpt.c +++ b/util-linux/fdisk_gpt.c | |||
@@ -177,7 +177,7 @@ check_gpt_label(void) | |||
177 | 177 | ||
178 | init_unicode(); | 178 | init_unicode(); |
179 | if (!global_crc32_table) { | 179 | if (!global_crc32_table) { |
180 | global_crc32_table = crc32_filltable(NULL, 0); | 180 | global_crc32_new_table_le(); |
181 | } | 181 | } |
182 | 182 | ||
183 | crc = SWAP_LE32(gpt_hdr->hdr_crc32); | 183 | crc = SWAP_LE32(gpt_hdr->hdr_crc32); |