diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-14 00:06:29 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-03-14 00:06:29 +0000 |
| commit | da799e82274ffa48c5a27c5d034f4f31ba06e29f (patch) | |
| tree | 9cc8813b722a7180b5545e31dfc5cf30631c4b1b | |
| parent | e930fe14413e0171d623010c4f7ff1152d58e8ab (diff) | |
| download | busybox-w32-da799e82274ffa48c5a27c5d034f4f31ba06e29f.tar.gz busybox-w32-da799e82274ffa48c5a27c5d034f4f31ba06e29f.tar.bz2 busybox-w32-da799e82274ffa48c5a27c5d034f4f31ba06e29f.zip | |
gzip: reduce global data footprint, part 2
| -rw-r--r-- | archival/gzip.c | 90 | ||||
| -rw-r--r-- | libbb/messages.c | 2 |
2 files changed, 48 insertions, 44 deletions
diff --git a/archival/gzip.c b/archival/gzip.c index aa88fd7e5..76ee1cf58 100644 --- a/archival/gzip.c +++ b/archival/gzip.c | |||
| @@ -197,6 +197,9 @@ typedef int32_t lng; | |||
| 197 | 197 | ||
| 198 | typedef ush Pos; | 198 | typedef ush Pos; |
| 199 | typedef unsigned IPos; | 199 | typedef unsigned IPos; |
| 200 | /* A Pos is an index in the character window. We use short instead of int to | ||
| 201 | * save space in the various tables. IPos is used only for parameter passing. | ||
| 202 | */ | ||
| 200 | 203 | ||
| 201 | enum { | 204 | enum { |
| 202 | WINDOW_SIZE = 2 * WSIZE, | 205 | WINDOW_SIZE = 2 * WSIZE, |
| @@ -238,11 +241,8 @@ enum { | |||
| 238 | }; | 241 | }; |
| 239 | 242 | ||
| 240 | 243 | ||
| 241 | struct G1 { | 244 | struct global1 { |
| 242 | 245 | ||
| 243 | /* A Pos is an index in the character window. We use short instead of int to | ||
| 244 | * save space in the various tables. IPos is used only for parameter passing. | ||
| 245 | */ | ||
| 246 | lng block_start; | 246 | lng block_start; |
| 247 | 247 | ||
| 248 | /* window position at the beginning of the current output block. Gets | 248 | /* window position at the beginning of the current output block. Gets |
| @@ -266,7 +266,6 @@ struct G1 { | |||
| 266 | unsigned strstart; /* start of string to insert */ | 266 | unsigned strstart; /* start of string to insert */ |
| 267 | unsigned match_start; /* start of matching string */ | 267 | unsigned match_start; /* start of matching string */ |
| 268 | unsigned lookahead; /* number of valid bytes ahead in window */ | 268 | unsigned lookahead; /* number of valid bytes ahead in window */ |
| 269 | smallint eofile; /* flag set at end of input file */ | ||
| 270 | 269 | ||
| 271 | /* =========================================================================== | 270 | /* =========================================================================== |
| 272 | */ | 271 | */ |
| @@ -318,6 +317,7 @@ struct G1 { | |||
| 318 | /* original time stamp (modification time) */ | 317 | /* original time stamp (modification time) */ |
| 319 | ulg time_stamp; /* only 32 bits stored in .gz file */ | 318 | ulg time_stamp; /* only 32 bits stored in .gz file */ |
| 320 | 319 | ||
| 320 | //TODO: get rid of this | ||
| 321 | int ifd; /* input file descriptor */ | 321 | int ifd; /* input file descriptor */ |
| 322 | int ofd; /* output file descriptor */ | 322 | int ofd; /* output file descriptor */ |
| 323 | #ifdef DEBUG | 323 | #ifdef DEBUG |
| @@ -325,8 +325,7 @@ struct G1 { | |||
| 325 | #endif | 325 | #endif |
| 326 | unsigned outcnt; /* bytes in output buffer */ | 326 | unsigned outcnt; /* bytes in output buffer */ |
| 327 | 327 | ||
| 328 | uint32_t *crc_32_tab; | 328 | smallint eofile; /* flag set at end of input file */ |
| 329 | |||
| 330 | 329 | ||
| 331 | /* =========================================================================== | 330 | /* =========================================================================== |
| 332 | * Local data used by the "bit string" routines. | 331 | * Local data used by the "bit string" routines. |
| @@ -352,10 +351,12 @@ struct G1 { | |||
| 352 | ulg bits_sent; /* bit length of the compressed data */ | 351 | ulg bits_sent; /* bit length of the compressed data */ |
| 353 | #endif | 352 | #endif |
| 354 | 353 | ||
| 354 | uint32_t *crc_32_tab; | ||
| 355 | uint32_t crc; /* shift register contents */ | 355 | uint32_t crc; /* shift register contents */ |
| 356 | }; | 356 | }; |
| 357 | 357 | ||
| 358 | static struct G1 G1; | 358 | extern struct global1 *global_ptr; |
| 359 | #define G1 (*(global_ptr - 1)) | ||
| 359 | 360 | ||
| 360 | 361 | ||
| 361 | /* =========================================================================== | 362 | /* =========================================================================== |
| @@ -880,7 +881,7 @@ typedef struct tree_desc { | |||
| 880 | int max_code; /* largest code with non zero frequency */ | 881 | int max_code; /* largest code with non zero frequency */ |
| 881 | } tree_desc; | 882 | } tree_desc; |
| 882 | 883 | ||
| 883 | struct G2 { | 884 | struct global2 { |
| 884 | 885 | ||
| 885 | ush heap[HEAP_SIZE]; /* heap used to build the Huffman trees */ | 886 | ush heap[HEAP_SIZE]; /* heap used to build the Huffman trees */ |
| 886 | int heap_len; /* number of elements in the heap */ | 887 | int heap_len; /* number of elements in the heap */ |
| @@ -971,23 +972,8 @@ struct G2 { | |||
| 971 | 972 | ||
| 972 | }; | 973 | }; |
| 973 | 974 | ||
| 974 | static struct G2 *G2ptr; | 975 | #define G2ptr ((struct global2*)(global_ptr)) |
| 975 | #define G2 (*G2ptr) | 976 | #define G2 (*G2ptr) |
| 976 | /* { | ||
| 977 | .l_desc = { | ||
| 978 | G2.dyn_ltree, G2.static_ltree, extra_lbits, | ||
| 979 | LITERALS + 1, L_CODES, MAX_BITS, 0 | ||
| 980 | }, | ||
| 981 | .d_desc = { | ||
| 982 | G2.dyn_dtree, G2.static_dtree, extra_dbits, | ||
| 983 | 0, D_CODES, MAX_BITS, 0 | ||
| 984 | }, | ||
| 985 | .bl_desc = { | ||
| 986 | G2.bl_tree, NULL, extra_blbits, | ||
| 987 | 0, BL_CODES, MAX_BL_BITS, 0 | ||
| 988 | } | ||
| 989 | }; | ||
| 990 | */ | ||
| 991 | 977 | ||
| 992 | 978 | ||
| 993 | /* =========================================================================== | 979 | /* =========================================================================== |
| @@ -2045,7 +2031,7 @@ static void ct_init(void) ////ush * attr, int *methodp) | |||
| 2045 | 2031 | ||
| 2046 | static void zip(int in, int out) | 2032 | static void zip(int in, int out) |
| 2047 | { | 2033 | { |
| 2048 | uch my_flags = 0; /* general purpose bit flags */ | 2034 | //// uch my_flags = 0; /* general purpose bit flags */ |
| 2049 | //// ush attr = 0; /* ascii/binary flag */ | 2035 | //// ush attr = 0; /* ascii/binary flag */ |
| 2050 | ush deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */ | 2036 | ush deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */ |
| 2051 | //// int method = DEFLATED; /* compression method */ | 2037 | //// int method = DEFLATED; /* compression method */ |
| @@ -2056,11 +2042,15 @@ static void zip(int in, int out) | |||
| 2056 | 2042 | ||
| 2057 | /* Write the header to the gzip file. See algorithm.doc for the format */ | 2043 | /* Write the header to the gzip file. See algorithm.doc for the format */ |
| 2058 | 2044 | ||
| 2059 | put_header_byte(0x1f); /* magic header for gzip files, 1F 8B */ | 2045 | //put_header_byte(0x1f); /* magic header for gzip files, 1F 8B */ |
| 2060 | put_header_byte(0x8b); | 2046 | //put_header_byte(0x8b); |
| 2061 | ////put_header_byte(DEFLATED); /* compression method */ | 2047 | //////put_header_byte(DEFLATED); /* compression method */ |
| 2062 | put_header_byte(8); /* compression method */ | 2048 | //put_header_byte(8); /* compression method */ |
| 2063 | put_header_byte(my_flags); /* general flags */ | 2049 | //put_header_byte(0); /* general flags */ |
| 2050 | /* magic header for gzip files: 1F 8B */ | ||
| 2051 | /* compression method: 8 */ | ||
| 2052 | /* general flags: 0 */ | ||
| 2053 | put_32bit(0x00088b1f); | ||
| 2064 | put_32bit(G1.time_stamp); | 2054 | put_32bit(G1.time_stamp); |
| 2065 | 2055 | ||
| 2066 | /* Write deflated file to zip file */ | 2056 | /* Write deflated file to zip file */ |
| @@ -2141,19 +2131,31 @@ int gzip_main(int argc, char **argv) | |||
| 2141 | } | 2131 | } |
| 2142 | #endif | 2132 | #endif |
| 2143 | 2133 | ||
| 2144 | G2ptr = xzalloc(sizeof(*G2ptr)); | 2134 | global_ptr = xzalloc(sizeof(struct global1) + sizeof(struct global2)); |
| 2145 | G2.l_desc = (tree_desc) { | 2135 | global_ptr++; |
| 2146 | G2.dyn_ltree, G2.static_ltree, extra_lbits, | 2136 | G2.l_desc.dyn_tree = G2.dyn_ltree; |
| 2147 | LITERALS + 1, L_CODES, MAX_BITS, 0 | 2137 | G2.l_desc.static_tree = G2.static_ltree; |
| 2148 | }; | 2138 | G2.l_desc.extra_bits = extra_lbits; |
| 2149 | G2.d_desc = (tree_desc) { | 2139 | G2.l_desc.extra_base = LITERALS + 1; |
| 2150 | G2.dyn_dtree, G2.static_dtree, extra_dbits, | 2140 | G2.l_desc.elems = L_CODES; |
| 2151 | 0, D_CODES, MAX_BITS, 0 | 2141 | G2.l_desc.max_length = MAX_BITS; |
| 2152 | }; | 2142 | //G2.l_desc.max_code = 0; |
| 2153 | G2.bl_desc = (tree_desc) { | 2143 | |
| 2154 | G2.bl_tree, NULL, extra_blbits, | 2144 | G2.d_desc.dyn_tree = G2.dyn_dtree; |
| 2155 | 0, BL_CODES, MAX_BL_BITS, 0 | 2145 | G2.d_desc.static_tree = G2.static_dtree; |
| 2156 | }; | 2146 | G2.d_desc.extra_bits = extra_dbits; |
| 2147 | //G2.d_desc.extra_base = 0; | ||
| 2148 | G2.d_desc.elems = D_CODES; | ||
| 2149 | G2.d_desc.max_length = MAX_BITS; | ||
| 2150 | //G2.d_desc.max_code = 0; | ||
| 2151 | |||
| 2152 | G2.bl_desc.dyn_tree = G2.bl_tree; | ||
| 2153 | //G2.bl_desc.static_tree = NULL; | ||
| 2154 | G2.bl_desc.extra_bits = extra_blbits, | ||
| 2155 | //G2.bl_desc.extra_base = 0; | ||
| 2156 | G2.bl_desc.elems = BL_CODES; | ||
| 2157 | G2.bl_desc.max_length = MAX_BL_BITS; | ||
| 2158 | //G2.bl_desc.max_code = 0; | ||
| 2157 | 2159 | ||
| 2158 | /* Allocate all global buffers (for DYN_ALLOC option) */ | 2160 | /* Allocate all global buffers (for DYN_ALLOC option) */ |
| 2159 | ALLOC(uch, G1.l_buf, INBUFSIZ); | 2161 | ALLOC(uch, G1.l_buf, INBUFSIZ); |
diff --git a/libbb/messages.c b/libbb/messages.c index 105e4ce66..7f23d4b6d 100644 --- a/libbb/messages.c +++ b/libbb/messages.c | |||
| @@ -55,3 +55,5 @@ WTMP_FILE; | |||
| 55 | #endif | 55 | #endif |
| 56 | 56 | ||
| 57 | char bb_common_bufsiz1[BUFSIZ+1]; | 57 | char bb_common_bufsiz1[BUFSIZ+1]; |
| 58 | |||
| 59 | void *global_ptr; | ||
