-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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%.
- Loading branch information
Showing
3 changed files
with
67 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -493,7 +493,11 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, | |
* symbols from which it is being constructed. | ||
*/ | ||
|
||
#ifdef LIT_MEM | ||
s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 5); | ||
#else | ||
s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 4); | ||
#endif | ||
s->pending_buf_size = (ulg)s->lit_bufsize * 4; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
madler
Author
Owner
|
||
|
||
if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || | ||
|
@@ -503,8 +507,14 @@ int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, | |
deflateEnd (strm); | ||
return Z_MEM_ERROR; | ||
} | ||
#ifdef LIT_MEM | ||
s->d_buf = (ushf *)(s->pending_buf + (s->lit_bufsize << 1)); | ||
s->l_buf = s->pending_buf + (s->lit_bufsize << 2); | ||
s->sym_end = s->lit_bufsize - 1; | ||
#else | ||
s->sym_buf = s->pending_buf + s->lit_bufsize; | ||
s->sym_end = (s->lit_bufsize - 1) * 3; | ||
#endif | ||
/* We avoid equality with lit_bufsize*3 because of wraparound at 64K | ||
* on 16 bit machines and because stored blocks are restricted to | ||
* 64K-1 bytes. | ||
|
@@ -720,9 +730,15 @@ int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) { | |
|
||
if (deflateStateCheck(strm)) return Z_STREAM_ERROR; | ||
s = strm->state; | ||
#ifdef LIT_MEM | ||
if (bits < 0 || bits > 16 || | ||
(uchf *)s->d_buf < s->pending_out + ((Buf_size + 7) >> 3)) | ||
return Z_BUF_ERROR; | ||
#else | ||
if (bits < 0 || bits > 16 || | ||
s->sym_buf < s->pending_out + ((Buf_size + 7) >> 3)) | ||
return Z_BUF_ERROR; | ||
#endif | ||
do { | ||
put = Buf_size - s->bi_valid; | ||
if (put > bits) | ||
|
@@ -1308,7 +1324,12 @@ int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) { | |
zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); | ||
|
||
ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); | ||
#ifdef LIT_MEM | ||
ds->d_buf = (ushf *)(ds->pending_buf + (ds->lit_bufsize << 1)); | ||
ds->l_buf = ds->pending_buf + (ds->lit_bufsize << 2); | ||
#else | ||
ds->sym_buf = ds->pending_buf + ds->lit_bufsize; | ||
#endif | ||
|
||
ds->l_desc.dyn_tree = ds->dyn_ltree; | ||
ds->d_desc.dyn_tree = ds->dyn_dtree; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@madler should
s->pending_buf_size = (ulg)s->lit_bufsize * 5;
whenLIT_MEM
is set?