Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: third_party/zlib/deflate.c

Issue 552123005: Integrate SIMD optimisations for zlib (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Singleton on Windows, add reference frame data from optimised version Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* deflate.c -- compress data using the deflation algorithm 1 /* deflate.c -- compress data using the deflation algorithm
2 * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler 2 * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6 /* 6 /*
7 * ALGORITHM 7 * ALGORITHM
8 * 8 *
9 * The "deflation" process depends on being able to identify portions 9 * The "deflation" process depends on being able to identify portions
10 * of the input text which are identical to earlier input (within a 10 * of the input text which are identical to earlier input (within a
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. 43 * "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
44 * 44 *
45 * Fiala,E.R., and Greene,D.H. 45 * Fiala,E.R., and Greene,D.H.
46 * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 46 * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595
47 * 47 *
48 */ 48 */
49 49
50 /* @(#) $Id$ */ 50 /* @(#) $Id$ */
51 51
52 #include "deflate.h" 52 #include "deflate.h"
53 #include "x86.h"
53 54
54 const char deflate_copyright[] = 55 const char deflate_copyright[] =
55 " deflate 1.2.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler "; 56 " deflate 1.2.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler ";
56 /* 57 /*
57 If you use the zlib library in a product, an acknowledgment is welcome 58 If you use the zlib library in a product, an acknowledgment is welcome
58 in the documentation of your product. If for some reason you cannot 59 in the documentation of your product. If for some reason you cannot
59 include such an acknowledgment, I would appreciate that you keep this 60 include such an acknowledgment, I would appreciate that you keep this
60 copyright string in the executable of your product. 61 copyright string in the executable of your product.
61 */ 62 */
62 63
(...skipping 15 matching lines...) Expand all
78 local block_state deflate_stored OF((deflate_state *s, int flush, int clas)); 79 local block_state deflate_stored OF((deflate_state *s, int flush, int clas));
79 local block_state deflate_fast OF((deflate_state *s, int flush, int clas)); 80 local block_state deflate_fast OF((deflate_state *s, int flush, int clas));
80 #ifndef FASTEST 81 #ifndef FASTEST
81 local block_state deflate_slow OF((deflate_state *s, int flush, int clas)); 82 local block_state deflate_slow OF((deflate_state *s, int flush, int clas));
82 #endif 83 #endif
83 local block_state deflate_rle OF((deflate_state *s, int flush)); 84 local block_state deflate_rle OF((deflate_state *s, int flush));
84 local block_state deflate_huff OF((deflate_state *s, int flush)); 85 local block_state deflate_huff OF((deflate_state *s, int flush));
85 local void lm_init OF((deflate_state *s)); 86 local void lm_init OF((deflate_state *s));
86 local void putShortMSB OF((deflate_state *s, uInt b)); 87 local void putShortMSB OF((deflate_state *s, uInt b));
87 local void flush_pending OF((z_streamp strm)); 88 local void flush_pending OF((z_streamp strm));
88 local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); 89
89 #ifdef ASMV 90 #ifdef ASMV
90 void match_init OF((void)); /* asm code initialization */ 91 void match_init OF((void)); /* asm code initialization */
91 uInt longest_match OF((deflate_state *s, IPos cur_match, int clas)); 92 uInt longest_match OF((deflate_state *s, IPos cur_match, int clas));
92 #else 93 #else
93 local uInt longest_match OF((deflate_state *s, IPos cur_match, int clas)); 94 local uInt longest_match OF((deflate_state *s, IPos cur_match, int clas));
94 #endif 95 #endif
95 96
96 #ifdef DEBUG 97 #ifdef DEBUG
97 local void check_match OF((deflate_state *s, IPos start, IPos match, 98 local void check_match OF((deflate_state *s, IPos start, IPos match,
98 int length)); 99 int length));
99 #endif 100 #endif
100 101
102 /* For fill_window_sse.c to use */
103 ZLIB_INTERNAL int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
104
105 /* From crc32.c */
106 extern void ZLIB_INTERNAL crc_reset(deflate_state *const s);
107 extern void ZLIB_INTERNAL crc_finalize(deflate_state *const s);
108 extern void ZLIB_INTERNAL copy_with_crc(z_streamp strm, Bytef *dst, long size);
109
101 /* =========================================================================== 110 /* ===========================================================================
102 * Local data 111 * Local data
103 */ 112 */
104 113
105 #define NIL 0 114 #define NIL 0
106 /* Tail of hash chains */ 115 /* Tail of hash chains */
107 116
108 #ifndef TOO_FAR 117 #ifndef TOO_FAR
109 # define TOO_FAR 4096 118 # define TOO_FAR 4096
110 #endif 119 #endif
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 #endif 166 #endif
158 167
159 /* =========================================================================== 168 /* ===========================================================================
160 * Update a hash value with the given input byte 169 * Update a hash value with the given input byte
161 * IN assertion: all calls to to UPDATE_HASH are made with consecutive 170 * IN assertion: all calls to to UPDATE_HASH are made with consecutive
162 * input characters, so that a running hash key can be computed from the 171 * input characters, so that a running hash key can be computed from the
163 * previous key instead of complete recalculation each time. 172 * previous key instead of complete recalculation each time.
164 */ 173 */
165 #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask) 174 #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
166 175
176 #ifdef _MSC_VER
177 #define INLINE __inline
178 #else
179 #define INLINE inline
180 #endif
167 181
168 /* =========================================================================== 182 /* ===========================================================================
169 * Insert string str in the dictionary and set match_head to the previous head 183 * Insert string str in the dictionary and set match_head to the previous head
170 * of the hash chain (the most recent string with same hash key). Return 184 * of the hash chain (the most recent string with same hash key). Return
171 * the previous length of the hash chain. 185 * the previous length of the hash chain.
172 * If this file is compiled with -DFASTEST, the compression level is forced 186 * If this file is compiled with -DFASTEST, the compression level is forced
173 * to 1, and no hash chains are maintained. 187 * to 1, and no hash chains are maintained.
174 * IN assertion: all calls to to INSERT_STRING are made with consecutive 188 * IN assertion: all calls to to INSERT_STRING are made with consecutive
175 * input characters and the first MIN_MATCH bytes of str are valid 189 * input characters and the first MIN_MATCH bytes of str are valid
176 * (except for the last MIN_MATCH-1 bytes of the input file). 190 * (except for the last MIN_MATCH-1 bytes of the input file).
177 */ 191 */
192 local INLINE Pos insert_string_c(deflate_state *const s, const Pos str)
193 {
194 Pos ret;
195
196 UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]);
178 #ifdef FASTEST 197 #ifdef FASTEST
179 #define INSERT_STRING(s, str, match_head) \ 198 ret = s->head[s->ins_h];
180 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
181 match_head = s->head[s->ins_h], \
182 s->head[s->ins_h] = (Pos)(str))
183 #else 199 #else
184 #define INSERT_STRING(s, str, match_head) \ 200 ret = s->prev[str & s->w_mask] = s->head[s->ins_h];
185 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
186 match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
187 s->head[s->ins_h] = (Pos)(str))
188 #endif 201 #endif
202 s->head[s->ins_h] = str;
203
204 return ret;
205 }
206
207 local INLINE Pos insert_string(deflate_state *const s, const Pos str)
208 {
209 if (x86_cpu_enable_simd)
210 return insert_string_sse(s, str);
211 return insert_string_c(s, str);
212 }
213
189 214
190 /* =========================================================================== 215 /* ===========================================================================
191 * Initialize the hash table (avoiding 64K overflow for 16 bit systems). 216 * Initialize the hash table (avoiding 64K overflow for 16 bit systems).
192 * prev[] will be initialized on the fly. 217 * prev[] will be initialized on the fly.
193 */ 218 */
194 #define CLEAR_HASH(s) \ 219 #define CLEAR_HASH(s) \
195 s->head[s->hash_size-1] = NIL; \ 220 s->head[s->hash_size-1] = NIL; \
196 zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); 221 zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
197 222
198 /* ========================================================================= */ 223 /* ========================================================================= */
(...skipping 13 matching lines...) Expand all
212 version, stream_size) 237 version, stream_size)
213 z_streamp strm; 238 z_streamp strm;
214 int level; 239 int level;
215 int method; 240 int method;
216 int windowBits; 241 int windowBits;
217 int memLevel; 242 int memLevel;
218 int strategy; 243 int strategy;
219 const char *version; 244 const char *version;
220 int stream_size; 245 int stream_size;
221 { 246 {
247 unsigned window_padding = 8;
222 deflate_state *s; 248 deflate_state *s;
223 int wrap = 1; 249 int wrap = 1;
224 static const char my_version[] = ZLIB_VERSION; 250 static const char my_version[] = ZLIB_VERSION;
225 251
226 ushf *overlay; 252 ushf *overlay;
227 /* We overlay pending_buf and d_buf+l_buf. This works since the average 253 /* We overlay pending_buf and d_buf+l_buf. This works since the average
228 * output size for (length,distance) codes is <= 24 bits. 254 * output size for (length,distance) codes is <= 24 bits.
229 */ 255 */
230 256
257 x86_check_features();
258
231 if (version == Z_NULL || version[0] != my_version[0] || 259 if (version == Z_NULL || version[0] != my_version[0] ||
232 stream_size != sizeof(z_stream)) { 260 stream_size != sizeof(z_stream)) {
233 return Z_VERSION_ERROR; 261 return Z_VERSION_ERROR;
234 } 262 }
235 if (strm == Z_NULL) return Z_STREAM_ERROR; 263 if (strm == Z_NULL) return Z_STREAM_ERROR;
236 264
237 strm->msg = Z_NULL; 265 strm->msg = Z_NULL;
238 if (strm->zalloc == (alloc_func)0) { 266 if (strm->zalloc == (alloc_func)0) {
239 strm->zalloc = zcalloc; 267 strm->zalloc = zcalloc;
240 strm->opaque = (voidpf)0; 268 strm->opaque = (voidpf)0;
(...skipping 26 matching lines...) Expand all
267 if (s == Z_NULL) return Z_MEM_ERROR; 295 if (s == Z_NULL) return Z_MEM_ERROR;
268 strm->state = (struct internal_state FAR *)s; 296 strm->state = (struct internal_state FAR *)s;
269 s->strm = strm; 297 s->strm = strm;
270 298
271 s->wrap = wrap; 299 s->wrap = wrap;
272 s->gzhead = Z_NULL; 300 s->gzhead = Z_NULL;
273 s->w_bits = windowBits; 301 s->w_bits = windowBits;
274 s->w_size = 1 << s->w_bits; 302 s->w_size = 1 << s->w_bits;
275 s->w_mask = s->w_size - 1; 303 s->w_mask = s->w_size - 1;
276 304
305 if (x86_cpu_enable_simd)
306 s->hash_bits = 15;
307 else
277 s->hash_bits = memLevel + 7; 308 s->hash_bits = memLevel + 7;
agl 2014/10/17 00:45:34 indentation. (Also, I think that omitting branches
robert.bradford 2014/10/20 16:45:54 Urgh I agree. Fixed. I'll try and get it fixed in
309
278 s->hash_size = 1 << s->hash_bits; 310 s->hash_size = 1 << s->hash_bits;
279 s->hash_mask = s->hash_size - 1; 311 s->hash_mask = s->hash_size - 1;
280 s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); 312 s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
281 313
282 s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); 314 s->window = (Bytef *) ZALLOC(strm, s->w_size + window_padding, 2*sizeof(Byte ));
283 s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); 315 s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
284 s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); 316 s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
285 s->class_bitmap = NULL; 317 s->class_bitmap = NULL;
286 zmemzero(&s->cookie_locations, sizeof(s->cookie_locations)); 318 zmemzero(&s->cookie_locations, sizeof(s->cookie_locations));
287 strm->clas = 0; 319 strm->clas = 0;
288 320
289 s->high_water = 0; /* nothing written to s->window yet */ 321 s->high_water = 0; /* nothing written to s->window yet */
290 322
291 s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ 323 s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
292 324
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 s->strstart = length; 372 s->strstart = length;
341 s->block_start = (long)length; 373 s->block_start = (long)length;
342 374
343 /* Insert all strings in the hash table (except for the last two bytes). 375 /* Insert all strings in the hash table (except for the last two bytes).
344 * s->lookahead stays null, so s->ins_h will be recomputed at the next 376 * s->lookahead stays null, so s->ins_h will be recomputed at the next
345 * call of fill_window. 377 * call of fill_window.
346 */ 378 */
347 s->ins_h = s->window[0]; 379 s->ins_h = s->window[0];
348 UPDATE_HASH(s, s->ins_h, s->window[1]); 380 UPDATE_HASH(s, s->ins_h, s->window[1]);
349 for (n = 0; n <= length - MIN_MATCH; n++) { 381 for (n = 0; n <= length - MIN_MATCH; n++) {
350 INSERT_STRING(s, n, hash_head); 382 insert_string(s, n);
351 } 383 }
352 if (hash_head) hash_head = 0; /* to make compiler happy */ 384 if (hash_head) hash_head = 0; /* to make compiler happy */
353 return Z_OK; 385 return Z_OK;
354 } 386 }
355 387
356 /* ========================================================================= */ 388 /* ========================================================================= */
357 int ZEXPORT deflateReset (strm) 389 int ZEXPORT deflateReset (strm)
358 z_streamp strm; 390 z_streamp strm;
359 { 391 {
360 deflate_state *s; 392 deflate_state *s;
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); 638 if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
607 639
608 s->strm = strm; /* just in case */ 640 s->strm = strm; /* just in case */
609 old_flush = s->last_flush; 641 old_flush = s->last_flush;
610 s->last_flush = flush; 642 s->last_flush = flush;
611 643
612 /* Write the header */ 644 /* Write the header */
613 if (s->status == INIT_STATE) { 645 if (s->status == INIT_STATE) {
614 #ifdef GZIP 646 #ifdef GZIP
615 if (s->wrap == 2) { 647 if (s->wrap == 2) {
616 strm->adler = crc32(0L, Z_NULL, 0); 648 crc_reset(s);
617 put_byte(s, 31); 649 put_byte(s, 31);
618 put_byte(s, 139); 650 put_byte(s, 139);
619 put_byte(s, 8); 651 put_byte(s, 8);
620 if (s->gzhead == Z_NULL) { 652 if (s->gzhead == Z_NULL) {
621 put_byte(s, 0); 653 put_byte(s, 0);
622 put_byte(s, 0); 654 put_byte(s, 0);
623 put_byte(s, 0); 655 put_byte(s, 0);
624 put_byte(s, 0); 656 put_byte(s, 0);
625 put_byte(s, 0); 657 put_byte(s, 0);
626 put_byte(s, s->level == 9 ? 2 : 658 put_byte(s, s->level == 9 ? 2 :
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 } 916 }
885 } 917 }
886 Assert(strm->avail_out > 0, "bug2"); 918 Assert(strm->avail_out > 0, "bug2");
887 919
888 if (flush != Z_FINISH) return Z_OK; 920 if (flush != Z_FINISH) return Z_OK;
889 if (s->wrap <= 0) return Z_STREAM_END; 921 if (s->wrap <= 0) return Z_STREAM_END;
890 922
891 /* Write the trailer */ 923 /* Write the trailer */
892 #ifdef GZIP 924 #ifdef GZIP
893 if (s->wrap == 2) { 925 if (s->wrap == 2) {
926 crc_finalize(s);
894 put_byte(s, (Byte)(strm->adler & 0xff)); 927 put_byte(s, (Byte)(strm->adler & 0xff));
895 put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); 928 put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
896 put_byte(s, (Byte)((strm->adler >> 16) & 0xff)); 929 put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
897 put_byte(s, (Byte)((strm->adler >> 24) & 0xff)); 930 put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
898 put_byte(s, (Byte)(strm->total_in & 0xff)); 931 put_byte(s, (Byte)(strm->total_in & 0xff));
899 put_byte(s, (Byte)((strm->total_in >> 8) & 0xff)); 932 put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
900 put_byte(s, (Byte)((strm->total_in >> 16) & 0xff)); 933 put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
901 put_byte(s, (Byte)((strm->total_in >> 24) & 0xff)); 934 put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
902 } 935 }
903 else 936 else
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 #endif /* MAXSEG_64K */ 1039 #endif /* MAXSEG_64K */
1007 } 1040 }
1008 1041
1009 /* =========================================================================== 1042 /* ===========================================================================
1010 * Read a new buffer from the current input stream, update the adler32 1043 * Read a new buffer from the current input stream, update the adler32
1011 * and total number of bytes read. All deflate() input goes through 1044 * and total number of bytes read. All deflate() input goes through
1012 * this function so some applications may wish to modify it to avoid 1045 * this function so some applications may wish to modify it to avoid
1013 * allocating a large strm->next_in buffer and copying from it. 1046 * allocating a large strm->next_in buffer and copying from it.
1014 * (See also flush_pending()). 1047 * (See also flush_pending()).
1015 */ 1048 */
1016 local int read_buf(strm, buf, size) 1049 ZLIB_INTERNAL int read_buf(strm, buf, size)
1017 z_streamp strm; 1050 z_streamp strm;
1018 Bytef *buf; 1051 Bytef *buf;
1019 unsigned size; 1052 unsigned size;
1020 { 1053 {
1021 unsigned len = strm->avail_in; 1054 unsigned len = strm->avail_in;
1022 1055
1023 if (len > size) len = size; 1056 if (len > size) len = size;
1024 if (len == 0) return 0; 1057 if (len == 0) return 0;
1025 1058
1026 strm->avail_in -= len; 1059 strm->avail_in -= len;
1027 1060
1028 if (strm->state->wrap == 1) { 1061 #ifdef GZIP
1029 strm->adler = adler32(strm->adler, strm->next_in, len); 1062 if (strm->state->wrap == 2) {
1063 copy_with_crc(strm, buf, len);
1030 } 1064 }
1031 #ifdef GZIP 1065 else
1032 else if (strm->state->wrap == 2) { 1066 #endif
1033 strm->adler = crc32(strm->adler, strm->next_in, len); 1067 {
1068 zmemcpy(buf, strm->next_in, len);
1069 if (strm->state->wrap == 1)
1070 strm->adler = adler32(strm->adler, buf, len);
1034 } 1071 }
1035 #endif
1036 zmemcpy(buf, strm->next_in, len);
1037 strm->next_in += len; 1072 strm->next_in += len;
1038 strm->total_in += len; 1073 strm->total_in += len;
1039 1074
1040 return (int)len; 1075 return (int)len;
1041 } 1076 }
1042 1077
1043 /* =========================================================================== 1078 /* ===========================================================================
1044 * Initialize the "longest match" routines for a new zlib stream 1079 * Initialize the "longest match" routines for a new zlib stream
1045 */ 1080 */
1046 local void lm_init (s) 1081 local void lm_init (s)
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 /* =========================================================================== 1473 /* ===========================================================================
1439 * Fill the window when the lookahead becomes insufficient. 1474 * Fill the window when the lookahead becomes insufficient.
1440 * Updates strstart and lookahead. 1475 * Updates strstart and lookahead.
1441 * 1476 *
1442 * IN assertion: lookahead < MIN_LOOKAHEAD 1477 * IN assertion: lookahead < MIN_LOOKAHEAD
1443 * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD 1478 * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
1444 * At least one byte has been read, or avail_in == 0; reads are 1479 * At least one byte has been read, or avail_in == 0; reads are
1445 * performed for at least two bytes (required for the zip translate_eol 1480 * performed for at least two bytes (required for the zip translate_eol
1446 * option -- not supported here). 1481 * option -- not supported here).
1447 */ 1482 */
1448 local void fill_window(s) 1483 local void fill_window_c(deflate_state *s);
1484
1485 local void fill_window(deflate_state *s)
1486 {
1487 if (x86_cpu_enable_simd) {
1488 fill_window_sse(s);
1489 return;
1490 }
1491
1492 fill_window_c(s);
1493 }
1494
1495 local void fill_window_c(s)
1449 deflate_state *s; 1496 deflate_state *s;
1450 { 1497 {
1451 register unsigned n, m; 1498 register unsigned n, m;
1452 register Posf *p; 1499 register Posf *p;
1453 unsigned more; /* Amount of free space at the end of the window. */ 1500 unsigned more; /* Amount of free space at the end of the window. */
1454 uInt wsize = s->w_size; 1501 uInt wsize = s->w_size;
1455 1502
1456 do { 1503 do {
1457 more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); 1504 more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
1458 1505
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 return need_more; 1751 return need_more;
1705 } 1752 }
1706 if (s->lookahead == 0) break; /* flush the current block */ 1753 if (s->lookahead == 0) break; /* flush the current block */
1707 } 1754 }
1708 1755
1709 /* Insert the string window[strstart .. strstart+2] in the 1756 /* Insert the string window[strstart .. strstart+2] in the
1710 * dictionary, and set hash_head to the head of the hash chain: 1757 * dictionary, and set hash_head to the head of the hash chain:
1711 */ 1758 */
1712 hash_head = NIL; 1759 hash_head = NIL;
1713 if (s->lookahead >= MIN_MATCH) { 1760 if (s->lookahead >= MIN_MATCH) {
1714 INSERT_STRING(s, s->strstart, hash_head); 1761 hash_head = insert_string(s, s->strstart);
1715 } 1762 }
1716 1763
1717 /* Find the longest match, discarding those <= prev_length. 1764 /* Find the longest match, discarding those <= prev_length.
1718 * At this point we have always match_length < MIN_MATCH 1765 * At this point we have always match_length < MIN_MATCH
1719 */ 1766 */
1720 if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { 1767 if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
1721 /* To simplify the code, we prevent matches with the string 1768 /* To simplify the code, we prevent matches with the string
1722 * of window index 0 (in particular we have to avoid a match 1769 * of window index 0 (in particular we have to avoid a match
1723 * of the string with itself at the start of the input file). 1770 * of the string with itself at the start of the input file).
1724 */ 1771 */
(...skipping 10 matching lines...) Expand all
1735 1782
1736 /* Insert new strings in the hash table only if the match length 1783 /* Insert new strings in the hash table only if the match length
1737 * is not too large. This saves time but degrades compression. 1784 * is not too large. This saves time but degrades compression.
1738 */ 1785 */
1739 #ifndef FASTEST 1786 #ifndef FASTEST
1740 if (s->match_length <= s->max_insert_length && 1787 if (s->match_length <= s->max_insert_length &&
1741 s->lookahead >= MIN_MATCH) { 1788 s->lookahead >= MIN_MATCH) {
1742 s->match_length--; /* string at strstart already in table */ 1789 s->match_length--; /* string at strstart already in table */
1743 do { 1790 do {
1744 s->strstart++; 1791 s->strstart++;
1745 INSERT_STRING(s, s->strstart, hash_head); 1792 hash_head = insert_string(s, s->strstart);
1746 /* strstart never exceeds WSIZE-MAX_MATCH, so there are 1793 /* strstart never exceeds WSIZE-MAX_MATCH, so there are
1747 * always MIN_MATCH bytes ahead. 1794 * always MIN_MATCH bytes ahead.
1748 */ 1795 */
1749 } while (--s->match_length != 0); 1796 } while (--s->match_length != 0);
1750 s->strstart++; 1797 s->strstart++;
1751 } else 1798 } else
1752 #endif 1799 #endif
1753 { 1800 {
1754 s->strstart += s->match_length; 1801 s->strstart += s->match_length;
1755 s->match_length = 0; 1802 s->match_length = 0;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1814 return need_more; 1861 return need_more;
1815 } 1862 }
1816 if (s->lookahead == 0) break; /* flush the current block */ 1863 if (s->lookahead == 0) break; /* flush the current block */
1817 } 1864 }
1818 1865
1819 /* Insert the string window[strstart .. strstart+2] in the 1866 /* Insert the string window[strstart .. strstart+2] in the
1820 * dictionary, and set hash_head to the head of the hash chain: 1867 * dictionary, and set hash_head to the head of the hash chain:
1821 */ 1868 */
1822 hash_head = NIL; 1869 hash_head = NIL;
1823 if (s->lookahead >= MIN_MATCH) { 1870 if (s->lookahead >= MIN_MATCH) {
1824 INSERT_STRING(s, s->strstart, hash_head); 1871 hash_head = insert_string(s, s->strstart);
1825 } 1872 }
1826 1873
1827 /* Find the longest match, discarding those <= prev_length. 1874 /* Find the longest match, discarding those <= prev_length.
1828 */ 1875 */
1829 s->prev_length = s->match_length, s->prev_match = s->match_start; 1876 s->prev_length = s->match_length, s->prev_match = s->match_start;
1830 s->match_length = MIN_MATCH-1; 1877 s->match_length = MIN_MATCH-1;
1831 1878
1832 if (clas == Z_CLASS_COOKIE && first) { 1879 if (clas == Z_CLASS_COOKIE && first) {
1833 s->match_length = cookie_match(s, s->strstart, input_length); 1880 s->match_length = cookie_match(s, s->strstart, input_length);
1834 } else if (clas == Z_CLASS_STANDARD && 1881 } else if (clas == Z_CLASS_STANDARD &&
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 1930
1884 /* Insert in hash table all strings up to the end of the match. 1931 /* Insert in hash table all strings up to the end of the match.
1885 * strstart-1 and strstart are already inserted. If there is not 1932 * strstart-1 and strstart are already inserted. If there is not
1886 * enough lookahead, the last two strings are not inserted in 1933 * enough lookahead, the last two strings are not inserted in
1887 * the hash table. 1934 * the hash table.
1888 */ 1935 */
1889 s->lookahead -= s->prev_length-1; 1936 s->lookahead -= s->prev_length-1;
1890 s->prev_length -= 2; 1937 s->prev_length -= 2;
1891 do { 1938 do {
1892 if (++s->strstart <= max_insert) { 1939 if (++s->strstart <= max_insert) {
1893 INSERT_STRING(s, s->strstart, hash_head); 1940 hash_head = insert_string(s, s->strstart);
1894 } 1941 }
1895 } while (--s->prev_length != 0); 1942 } while (--s->prev_length != 0);
1896 s->match_available = 0; 1943 s->match_available = 0;
1897 s->match_length = MIN_MATCH-1; 1944 s->match_length = MIN_MATCH-1;
1898 s->strstart++; 1945 s->strstart++;
1899 1946
1900 if (bflush) FLUSH_BLOCK(s, 0); 1947 if (bflush) FLUSH_BLOCK(s, 0);
1901 1948
1902 } else if (s->match_available) { 1949 } else if (s->match_available) {
1903 /* If there was no match at the previous position, output a 1950 /* If there was no match at the previous position, output a
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
2024 s->match_length = 0; 2071 s->match_length = 0;
2025 Tracevv((stderr,"%c", s->window[s->strstart])); 2072 Tracevv((stderr,"%c", s->window[s->strstart]));
2026 _tr_tally_lit (s, s->window[s->strstart], bflush); 2073 _tr_tally_lit (s, s->window[s->strstart], bflush);
2027 s->lookahead--; 2074 s->lookahead--;
2028 s->strstart++; 2075 s->strstart++;
2029 if (bflush) FLUSH_BLOCK(s, 0); 2076 if (bflush) FLUSH_BLOCK(s, 0);
2030 } 2077 }
2031 FLUSH_BLOCK(s, flush == Z_FINISH); 2078 FLUSH_BLOCK(s, flush == Z_FINISH);
2032 return flush == Z_FINISH ? finish_done : block_done; 2079 return flush == Z_FINISH ? finish_done : block_done;
2033 } 2080 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698