2121# define GZIP
2222#endif
2323
24+ /* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at
25+ the cost of a larger memory footprint */
26+ /* #define LIT_MEM */
27+
2428/* ===========================================================================
2529 * Internal compression state.
2630 */
@@ -215,7 +219,12 @@ typedef struct internal_state {
215219 /* Depth of each subtree used as tie breaker for trees of equal frequency
216220 */
217221
222+ #ifdef LIT_MEM
223+ ushf * d_buf ; /* buffer for distances */
224+ uchf * l_buf ; /* buffer for literals/lengths */
225+ #else
218226 uchf * sym_buf ; /* buffer for distances and literals/lengths */
227+ #endif
219228
220229 uInt lit_bufsize ;
221230 /* Size of match buffer for literals/lengths. There are 4 reasons for
@@ -237,7 +246,7 @@ typedef struct internal_state {
237246 * - I can't count above 4
238247 */
239248
240- uInt sym_next ; /* running index in sym_buf */
249+ uInt sym_next ; /* running index in symbol buffer */
241250 uInt sym_end ; /* symbol table full when sym_next reaches this */
242251
243252 ulg opt_len ; /* bit length of current block with optimal trees */
@@ -316,6 +325,25 @@ void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
316325 extern const uch ZLIB_INTERNAL _dist_code [];
317326#endif
318327
328+ #ifdef LIT_MEM
329+ # define _tr_tally_lit (s , c , flush ) \
330+ { uch cc = (c); \
331+ s->d_buf[s->sym_next] = 0; \
332+ s->l_buf[s->sym_next++] = cc; \
333+ s->dyn_ltree[cc].Freq++; \
334+ flush = (s->sym_next == s->sym_end); \
335+ }
336+ # define _tr_tally_dist (s , distance , length , flush ) \
337+ { uch len = (uch)(length); \
338+ ush dist = (ush)(distance); \
339+ s->d_buf[s->sym_next] = dist; \
340+ s->l_buf[s->sym_next++] = len; \
341+ dist--; \
342+ s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
343+ s->dyn_dtree[d_code(dist)].Freq++; \
344+ flush = (s->sym_next == s->sym_end); \
345+ }
346+ #else
319347# define _tr_tally_lit (s , c , flush ) \
320348 { uch cc = (c); \
321349 s->sym_buf[s->sym_next++] = 0; \
@@ -335,6 +363,7 @@ void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf,
335363 s->dyn_dtree[d_code(dist)].Freq++; \
336364 flush = (s->sym_next == s->sym_end); \
337365 }
366+ #endif
338367#else
339368# define _tr_tally_lit (s , c , flush ) flush = _tr_tally(s, 0, c)
340369# define _tr_tally_dist (s , distance , length , flush ) \
0 commit comments