bzip2 decompression: simple code shrink
authorDenys Vlasenko <vda.linux@googlemail.com>
Wed, 30 Jun 2010 17:43:44 +0000 (19:43 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 30 Jun 2010 17:43:44 +0000 (19:43 +0200)
function                                             old     new   delta
unpack_bz2_stream_prime                               60      55      -5
get_header_tar                                      1508    1496     -12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
archival/libunarchive/decompress_bunzip2.c
archival/libunarchive/get_header_tar.c

index cd8df086e15ebe3191c521948f99b0c6b32ef243..bdbd39ac231ce96407bdab99c295c4d20074f857 100644 (file)
@@ -692,9 +692,9 @@ unpack_bz2_stream(int src_fd, int dst_fd)
 IF_DESKTOP(long long) int FAST_FUNC
 unpack_bz2_stream_prime(int src_fd, int dst_fd)
 {
-       unsigned char magic[2];
-       xread(src_fd, magic, 2);
-       if (magic[0] != 'B' || magic[1] != 'Z') {
+       uint16_t magic2;
+       xread(src_fd, &magic2, 2);
+       if (magic2 != BZIP2_MAGIC) {
                bb_error_msg_and_die("invalid magic");
        }
        return unpack_bz2_stream(src_fd, dst_fd);
index 21bbc97156f56a9b31a899712173705343c94d12..d5c92359c6c7fff05e802549cede01019ccecbf2 100644 (file)
@@ -196,27 +196,30 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
        ) {
 #if ENABLE_FEATURE_TAR_AUTODETECT
                char FAST_FUNC (*get_header_ptr)(archive_handle_t *);
+               uint16_t magic2;
 
  autodetect:
+               magic2 = *(uint16_t*)tar.name;
                /* tar gz/bz autodetect: check for gz/bz2 magic.
                 * If we see the magic, and it is the very first block,
                 * we can switch to get_header_tar_gz/bz2/lzma().
                 * Needs seekable fd. I wish recv(MSG_PEEK) works
                 * on any fd... */
 # if ENABLE_FEATURE_SEAMLESS_GZ
-               if (tar.name[0] == 0x1f && tar.name[1] == (char)0x8b) { /* gzip */
+               if (magic2 == GZIP_MAGIC) {
                        get_header_ptr = get_header_tar_gz;
                } else
 # endif
 # if ENABLE_FEATURE_SEAMLESS_BZ2
-               if (tar.name[0] == 'B' && tar.name[1] == 'Z'
+               if (magic2 == BZIP2_MAGIC
                 && tar.name[2] == 'h' && isdigit(tar.name[3])
                ) { /* bzip2 */
                        get_header_ptr = get_header_tar_bz2;
                } else
 # endif
 # if ENABLE_FEATURE_SEAMLESS_XZ
-               //TODO
+               //TODO: if (magic2 == XZ_MAGIC1)...
+               //else
 # endif
                        goto err;
                /* Two different causes for lseek() != 0: