libbb: commonalize a bit of little-endian CRC32 table generation code
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 1 Feb 2018 09:56:19 +0000 (10:56 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 1 Feb 2018 09:56:19 +0000 (10:56 +0100)
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>
archival/gzip.c
archival/libarchive/decompress_gunzip.c
archival/libarchive/decompress_unxz.c
archival/lzop.c
include/libbb.h
libbb/crc32.c
miscutils/flash_eraseall.c
util-linux/fdisk_gpt.c

index e3dd79291b5ec4029311cf85a321e0f5a344f6ea..c5a1fe9b4ec2558a9b2d9da7e0e58d3e0947f793 100644 (file)
@@ -2239,7 +2239,7 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
        ALLOC(ush, G1.prev, 1L << BITS);
 
        /* Initialize the CRC32 table */
-       global_crc32_table = crc32_filltable(NULL, 0);
+       global_crc32_new_table_le();
 
        argv += optind;
        return bbunpack(argv, pack_gzip, append_ext, "gz");
index c8245d73698c0e2157b4f85350b7230c4b130c4f..edff7e0e5d7de73fb5fa060b6e88e6884c9f9253 100644 (file)
@@ -1000,7 +1000,7 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
        gunzip_bb = 0;
 
        /* Create the crc table */
-       gunzip_crc_table = crc32_filltable(NULL, 0);
+       gunzip_crc_table = crc32_new_table_le();
        gunzip_crc = ~0;
 
        error_msg = "corrupted data";
index 0be85500ca9a3678ff8b9e689ad4b7bfdb0a341c..8ae7a275bfd71cfa4f563a0168e075e55fc07a5c 100644 (file)
@@ -52,7 +52,7 @@ unpack_xz_stream(transformer_state_t *xstate)
        IF_DESKTOP(long long) int total = 0;
 
        if (!global_crc32_table)
-               global_crc32_table = crc32_filltable(NULL, /*endian:*/ 0);
+               global_crc32_new_table_le();
 
        memset(&iobuf, 0, sizeof(iobuf));
        membuf = xmalloc(2 * BUFSIZ);
index ba27aeff0113fd7e2d83be367510a1627259fad1..fef8cdba368ba6c6e1d83789376741eaf3f54eff 100644 (file)
@@ -1148,6 +1148,6 @@ int lzop_main(int argc UNUSED_PARAM, char **argv)
        if (ENABLE_UNLZOP && applet_name[4] == 'o')
                option_mask32 |= OPT_DECOMPRESS;
 
-       global_crc32_table = crc32_filltable(NULL, 0);
+       global_crc32_new_table_le();
        return bbunpack(argv, pack_lzop, make_new_name_lzop, /*unused:*/ NULL);
 }
index a9386402085e79b647ca6967980ffa9abd131e23..2bb3643667d937cd3d79fc06bd38ec725e513c50 100644 (file)
@@ -1928,6 +1928,8 @@ typedef struct md5_ctx_t md5sha_ctx_t;
 
 extern uint32_t *global_crc32_table;
 uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC;
+uint32_t *crc32_new_table_le(void) FAST_FUNC;
+uint32_t *global_crc32_new_table_le(void) FAST_FUNC;
 uint32_t crc32_block_endian1(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) FAST_FUNC;
 uint32_t crc32_block_endian0(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) FAST_FUNC;
 
index b00b580d089ee4e005f1b13d994c7c5a54fb045b..728bcb73610c47505bb3e17c2458c1976e9922b0 100644 (file)
@@ -41,6 +41,16 @@ uint32_t* FAST_FUNC crc32_filltable(uint32_t *crc_table, int endian)
 
        return crc_table - 256;
 }
+/* Common uses: */
+uint32_t* FAST_FUNC crc32_new_table_le(void)
+{
+       return crc32_filltable(NULL, 0);
+}
+uint32_t* FAST_FUNC global_crc32_new_table_le(void)
+{
+       global_crc32_table = crc32_new_table_le();
+       return global_crc32_table;
+}
 
 uint32_t FAST_FUNC crc32_block_endian1(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table)
 {
index fab21291c4a7e4e8dc0c52958240dc61fa091b9e..8e93060ca9678940afc1b6c6ace4da1fbe1984fe 100644 (file)
@@ -101,7 +101,7 @@ int flash_eraseall_main(int argc UNUSED_PARAM, char **argv)
        if (flags & OPTION_J) {
                uint32_t *crc32_table;
 
-               crc32_table = crc32_filltable(NULL, 0);
+               crc32_table = crc32_new_table_le();
 
                cleanmarker.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
                cleanmarker.nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER);
index 45d2aa6e72b6312cd4c41e0ac43f09567780ceac..cdb90627daec785f9c2e13836bc5583a275bf5cd 100644 (file)
@@ -177,7 +177,7 @@ check_gpt_label(void)
 
        init_unicode();
        if (!global_crc32_table) {
-               global_crc32_table = crc32_filltable(NULL, 0);
+               global_crc32_new_table_le();
        }
 
        crc = SWAP_LE32(gpt_hdr->hdr_crc32);