aboutsummaryrefslogtreecommitdiff
path: root/trees.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2023-09-18 21:17:00 -0700
committerMark Adler <madler@alumni.caltech.edu>2023-09-21 00:14:56 -0700
commitac8f12c97d1afd9bafa9c710f827d40a407d3266 (patch)
treecc8841032d996c2f5c41d75c7edf65558d2d90ce /trees.c
parentbd9c329c1055a9265812352655ed2eec93f36e92 (diff)
downloadzlib-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 'trees.c')
-rw-r--r--trees.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/trees.c b/trees.c
index 8dbdc40..5ca23e9 100644
--- a/trees.c
+++ b/trees.c
@@ -899,14 +899,19 @@ local void compress_block(deflate_state *s, const ct_data *ltree,
899 const ct_data *dtree) { 899 const ct_data *dtree) {
900 unsigned dist; /* distance of matched string */ 900 unsigned dist; /* distance of matched string */
901 int lc; /* match length or unmatched char (if dist == 0) */ 901 int lc; /* match length or unmatched char (if dist == 0) */
902 unsigned sx = 0; /* running index in sym_buf */ 902 unsigned sx = 0; /* running index in symbol buffers */
903 unsigned code; /* the code to send */ 903 unsigned code; /* the code to send */
904 int extra; /* number of extra bits to send */ 904 int extra; /* number of extra bits to send */
905 905
906 if (s->sym_next != 0) do { 906 if (s->sym_next != 0) do {
907#ifdef LIT_MEM
908 dist = s->d_buf[sx];
909 lc = s->l_buf[sx++];
910#else
907 dist = s->sym_buf[sx++] & 0xff; 911 dist = s->sym_buf[sx++] & 0xff;
908 dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; 912 dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8;
909 lc = s->sym_buf[sx++]; 913 lc = s->sym_buf[sx++];
914#endif
910 if (dist == 0) { 915 if (dist == 0) {
911 send_code(s, lc, ltree); /* send a literal byte */ 916 send_code(s, lc, ltree); /* send a literal byte */
912 Tracecv(isgraph(lc), (stderr," '%c' ", lc)); 917 Tracecv(isgraph(lc), (stderr," '%c' ", lc));
@@ -931,8 +936,12 @@ local void compress_block(deflate_state *s, const ct_data *ltree,
931 } 936 }
932 } /* literal or match pair ? */ 937 } /* literal or match pair ? */
933 938
934 /* Check that the overlay between pending_buf and sym_buf is ok: */ 939 /* Check for no overlay of pending_buf on needed symbols */
940#ifdef LIT_MEM
941 Assert(s->pending < (s->lit_bufsize << 1) + sx, "pendingBuf overflow");
942#else
935 Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); 943 Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow");
944#endif
936 945
937 } while (sx < s->sym_next); 946 } while (sx < s->sym_next);
938 947
@@ -1082,9 +1091,14 @@ void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf,
1082 * the current block must be flushed. 1091 * the current block must be flushed.
1083 */ 1092 */
1084int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc) { 1093int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc) {
1094#ifdef LIT_MEM
1095 s->d_buf[s->sym_next] = (ush)dist;
1096 s->l_buf[s->sym_next++] = (uch)lc;
1097#else
1085 s->sym_buf[s->sym_next++] = (uch)dist; 1098 s->sym_buf[s->sym_next++] = (uch)dist;
1086 s->sym_buf[s->sym_next++] = (uch)(dist >> 8); 1099 s->sym_buf[s->sym_next++] = (uch)(dist >> 8);
1087 s->sym_buf[s->sym_next++] = (uch)lc; 1100 s->sym_buf[s->sym_next++] = (uch)lc;
1101#endif
1088 if (dist == 0) { 1102 if (dist == 0) {
1089 /* lc is the unmatched char */ 1103 /* lc is the unmatched char */
1090 s->dyn_ltree[lc].Freq++; 1104 s->dyn_ltree[lc].Freq++;