diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2016-10-30 09:25:32 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2016-12-04 07:39:25 -0800 |
commit | a456d898bb5d81a5e33705bfe2d476af8d4fee98 (patch) | |
tree | d2f0f998314fef139c0f101baf5b6e58e83853d7 /trees.c | |
parent | 03614c56ad299f9b238c75aa1e66f0c08fc4fc8b (diff) | |
download | zlib-a456d898bb5d81a5e33705bfe2d476af8d4fee98.tar.gz zlib-a456d898bb5d81a5e33705bfe2d476af8d4fee98.tar.bz2 zlib-a456d898bb5d81a5e33705bfe2d476af8d4fee98.zip |
Use memcpy for stored blocks.
This speeds up level 0 by about a factor of three, as compared to
the previous byte-at-a-time loop. We can do much better though. A
later commit avoids this copy for level 0 with large buffers,
instead copying directly from the input to the output. This commit
still speeds up storing incompressible data found when compressing
normally.
Diffstat (limited to 'trees.c')
-rw-r--r-- | trees.c | 37 |
1 files changed, 7 insertions, 30 deletions
@@ -152,8 +152,6 @@ local int detect_data_type OF((deflate_state *s)); | |||
152 | local unsigned bi_reverse OF((unsigned value, int length)); | 152 | local unsigned bi_reverse OF((unsigned value, int length)); |
153 | local void bi_windup OF((deflate_state *s)); | 153 | local void bi_windup OF((deflate_state *s)); |
154 | local void bi_flush OF((deflate_state *s)); | 154 | local void bi_flush OF((deflate_state *s)); |
155 | local void copy_block OF((deflate_state *s, charf *buf, unsigned len, | ||
156 | int header)); | ||
157 | 155 | ||
158 | #ifdef GEN_TREES_H | 156 | #ifdef GEN_TREES_H |
159 | local void gen_trees_header OF((void)); | 157 | local void gen_trees_header OF((void)); |
@@ -869,11 +867,17 @@ void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) | |||
869 | int last; /* one if this is the last block for a file */ | 867 | int last; /* one if this is the last block for a file */ |
870 | { | 868 | { |
871 | send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */ | 869 | send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */ |
870 | bi_windup(s); /* align on byte boundary */ | ||
871 | put_short(s, (ush)stored_len); | ||
872 | put_short(s, (ush)~stored_len); | ||
873 | zmemcpy(s->pending_buf + s->pending, buf, stored_len); | ||
874 | s->pending += stored_len; | ||
872 | #ifdef ZLIB_DEBUG | 875 | #ifdef ZLIB_DEBUG |
873 | s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; | 876 | s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; |
874 | s->compressed_len += (stored_len + 4) << 3; | 877 | s->compressed_len += (stored_len + 4) << 3; |
878 | s->bits_sent += 2*16; | ||
879 | s->bits_sent += stored_len<<3; | ||
875 | #endif | 880 | #endif |
876 | copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ | ||
877 | } | 881 | } |
878 | 882 | ||
879 | /* =========================================================================== | 883 | /* =========================================================================== |
@@ -1197,30 +1201,3 @@ local void bi_windup(s) | |||
1197 | s->bits_sent = (s->bits_sent+7) & ~7; | 1201 | s->bits_sent = (s->bits_sent+7) & ~7; |
1198 | #endif | 1202 | #endif |
1199 | } | 1203 | } |
1200 | |||
1201 | /* =========================================================================== | ||
1202 | * Copy a stored block, storing first the length and its | ||
1203 | * one's complement if requested. | ||
1204 | */ | ||
1205 | local void copy_block(s, buf, len, header) | ||
1206 | deflate_state *s; | ||
1207 | charf *buf; /* the input data */ | ||
1208 | unsigned len; /* its length */ | ||
1209 | int header; /* true if block header must be written */ | ||
1210 | { | ||
1211 | bi_windup(s); /* align on byte boundary */ | ||
1212 | |||
1213 | if (header) { | ||
1214 | put_short(s, (ush)len); | ||
1215 | put_short(s, (ush)~len); | ||
1216 | #ifdef ZLIB_DEBUG | ||
1217 | s->bits_sent += 2*16; | ||
1218 | #endif | ||
1219 | } | ||
1220 | #ifdef ZLIB_DEBUG | ||
1221 | s->bits_sent += (ulg)len<<3; | ||
1222 | #endif | ||
1223 | while (len--) { | ||
1224 | put_byte(s, *buf++); | ||
1225 | } | ||
1226 | } | ||