diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2023-09-18 21:17:00 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2023-09-21 00:14:56 -0700 |
commit | ac8f12c97d1afd9bafa9c710f827d40a407d3266 (patch) | |
tree | cc8841032d996c2f5c41d75c7edf65558d2d90ce /deflate.h | |
parent | bd9c329c1055a9265812352655ed2eec93f36e92 (diff) | |
download | zlib-ac8f12c97d1afd9bafa9c710f827d40a407d3266.tar.gz zlib-ac8f12c97d1afd9bafa9c710f827d40a407d3266.tar.bz2 zlib-ac8f12c97d1afd9bafa9c710f827d40a407d3266.zip |
Add LIT_MEM define to use more memory for a small deflate speedup.
A bug fix in zlib 1.2.12 resulted in a slight slowdown (1-2%) of
deflate. This commit provides the option to #define LIT_MEM, which
uses more memory to reverse most of that slowdown. The memory for
the pending buffer and symbol buffers is increased by 25%, which
increases the total memory usage with the default parameters by
about 6%.
Diffstat (limited to 'deflate.h')
-rw-r--r-- | deflate.h | 31 |
1 files changed, 30 insertions, 1 deletions
@@ -23,6 +23,10 @@ | |||
23 | # define GZIP | 23 | # define GZIP |
24 | #endif | 24 | #endif |
25 | 25 | ||
26 | /* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at | ||
27 | the cost of a larger memory footprint */ | ||
28 | /* #define LIT_MEM */ | ||
29 | |||
26 | /* =========================================================================== | 30 | /* =========================================================================== |
27 | * Internal compression state. | 31 | * Internal compression state. |
28 | */ | 32 | */ |
@@ -217,7 +221,12 @@ typedef struct internal_state { | |||
217 | /* Depth of each subtree used as tie breaker for trees of equal frequency | 221 | /* Depth of each subtree used as tie breaker for trees of equal frequency |
218 | */ | 222 | */ |
219 | 223 | ||
224 | #ifdef LIT_MEM | ||
225 | ushf *d_buf; /* buffer for distances */ | ||
226 | uchf *l_buf; /* buffer for literals/lengths */ | ||
227 | #else | ||
220 | uchf *sym_buf; /* buffer for distances and literals/lengths */ | 228 | uchf *sym_buf; /* buffer for distances and literals/lengths */ |
229 | #endif | ||
221 | 230 | ||
222 | uInt lit_bufsize; | 231 | uInt lit_bufsize; |
223 | /* Size of match buffer for literals/lengths. There are 4 reasons for | 232 | /* Size of match buffer for literals/lengths. There are 4 reasons for |
@@ -239,7 +248,7 @@ typedef struct internal_state { | |||
239 | * - I can't count above 4 | 248 | * - I can't count above 4 |
240 | */ | 249 | */ |
241 | 250 | ||
242 | uInt sym_next; /* running index in sym_buf */ | 251 | uInt sym_next; /* running index in symbol buffer */ |
243 | uInt sym_end; /* symbol table full when sym_next reaches this */ | 252 | uInt sym_end; /* symbol table full when sym_next reaches this */ |
244 | 253 | ||
245 | ulg opt_len; /* bit length of current block with optimal trees */ | 254 | ulg opt_len; /* bit length of current block with optimal trees */ |
@@ -318,6 +327,25 @@ void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, | |||
318 | extern const uch ZLIB_INTERNAL _dist_code[]; | 327 | extern const uch ZLIB_INTERNAL _dist_code[]; |
319 | #endif | 328 | #endif |
320 | 329 | ||
330 | #ifdef LIT_MEM | ||
331 | # define _tr_tally_lit(s, c, flush) \ | ||
332 | { uch cc = (c); \ | ||
333 | s->d_buf[s->sym_next] = 0; \ | ||
334 | s->l_buf[s->sym_next++] = cc; \ | ||
335 | s->dyn_ltree[cc].Freq++; \ | ||
336 | flush = (s->sym_next == s->sym_end); \ | ||
337 | } | ||
338 | # define _tr_tally_dist(s, distance, length, flush) \ | ||
339 | { uch len = (uch)(length); \ | ||
340 | ush dist = (ush)(distance); \ | ||
341 | s->d_buf[s->sym_next] = dist; \ | ||
342 | s->l_buf[s->sym_next++] = len; \ | ||
343 | dist--; \ | ||
344 | s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ | ||
345 | s->dyn_dtree[d_code(dist)].Freq++; \ | ||
346 | flush = (s->sym_next == s->sym_end); \ | ||
347 | } | ||
348 | #else | ||
321 | # define _tr_tally_lit(s, c, flush) \ | 349 | # define _tr_tally_lit(s, c, flush) \ |
322 | { uch cc = (c); \ | 350 | { uch cc = (c); \ |
323 | s->sym_buf[s->sym_next++] = 0; \ | 351 | s->sym_buf[s->sym_next++] = 0; \ |
@@ -337,6 +365,7 @@ void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, | |||
337 | s->dyn_dtree[d_code(dist)].Freq++; \ | 365 | s->dyn_dtree[d_code(dist)].Freq++; \ |
338 | flush = (s->sym_next == s->sym_end); \ | 366 | flush = (s->sym_next == s->sym_end); \ |
339 | } | 367 | } |
368 | #endif | ||
340 | #else | 369 | #else |
341 | # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) | 370 | # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) |
342 | # define _tr_tally_dist(s, distance, length, flush) \ | 371 | # define _tr_tally_dist(s, distance, length, flush) \ |