deflate.c (17651) | deflate.c (33904) |
---|---|
1/* deflate.c -- compress data using the deflation algorithm | 1/* deflate.c -- compress data using the deflation algorithm |
2 * Copyright (C) 1995-1996 Jean-loup Gailly. | 2 * Copyright (C) 1995-1998 Jean-loup Gailly. |
3 * For conditions of distribution and use, see copyright notice in zlib.h 4 */ 5 6/* 7 * ALGORITHM 8 * 9 * The "deflation" process depends on being able to identify portions 10 * of the input text which are identical to earlier input (within a --- 20 unchanged lines hidden (view full) --- 31 * ACKNOWLEDGEMENTS 32 * 33 * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and 34 * I found it in 'freeze' written by Leonid Broukhis. 35 * Thanks to many people for bug reports and testing. 36 * 37 * REFERENCES 38 * | 3 * For conditions of distribution and use, see copyright notice in zlib.h 4 */ 5 6/* 7 * ALGORITHM 8 * 9 * The "deflation" process depends on being able to identify portions 10 * of the input text which are identical to earlier input (within a --- 20 unchanged lines hidden (view full) --- 31 * ACKNOWLEDGEMENTS 32 * 33 * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and 34 * I found it in 'freeze' written by Leonid Broukhis. 35 * Thanks to many people for bug reports and testing. 36 * 37 * REFERENCES 38 * |
39 * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification". 40 * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc | 39 * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification". 40 * Available in ftp://ds.internic.net/rfc/rfc1951.txt |
41 * 42 * A description of the Rabin and Karp algorithm is given in the book 43 * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. 44 * 45 * Fiala,E.R., and Greene,D.H. 46 * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 47 * 48 */ 49 | 41 * 42 * A description of the Rabin and Karp algorithm is given in the book 43 * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. 44 * 45 * Fiala,E.R., and Greene,D.H. 46 * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 47 * 48 */ 49 |
50/* $Id: deflate.c,v 1.15 1996/07/24 13:40:58 me Exp $ */ | 50/* @(#) $Id$ */ |
51 52#include "deflate.h" 53 | 51 52#include "deflate.h" 53 |
54char deflate_copyright[] = " deflate 1.0.4 Copyright 1995-1996 Jean-loup Gailly "; | 54const char deflate_copyright[] = 55 " deflate 1.1.1 Copyright 1995-1998 Jean-loup Gailly "; |
55/* 56 If you use the zlib library in a product, an acknowledgment is welcome 57 in the documentation of your product. If for some reason you cannot 58 include such an acknowledgment, I would appreciate that you keep this 59 copyright string in the executable of your product. 60 */ 61 62/* =========================================================================== --- 9 unchanged lines hidden (view full) --- 72typedef block_state (*compress_func) OF((deflate_state *s, int flush)); 73/* Compression function. Returns the block state after the call. */ 74 75local void fill_window OF((deflate_state *s)); 76local block_state deflate_stored OF((deflate_state *s, int flush)); 77local block_state deflate_fast OF((deflate_state *s, int flush)); 78local block_state deflate_slow OF((deflate_state *s, int flush)); 79local void lm_init OF((deflate_state *s)); | 56/* 57 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 include such an acknowledgment, I would appreciate that you keep this 60 copyright string in the executable of your product. 61 */ 62 63/* =========================================================================== --- 9 unchanged lines hidden (view full) --- 73typedef block_state (*compress_func) OF((deflate_state *s, int flush)); 74/* Compression function. Returns the block state after the call. */ 75 76local void fill_window OF((deflate_state *s)); 77local block_state deflate_stored OF((deflate_state *s, int flush)); 78local block_state deflate_fast OF((deflate_state *s, int flush)); 79local block_state deflate_slow OF((deflate_state *s, int flush)); 80local void lm_init OF((deflate_state *s)); |
80local uInt longest_match OF((deflate_state *s, IPos cur_match)); | |
81local void putShortMSB OF((deflate_state *s, uInt b)); 82local void flush_pending OF((z_streamp strm)); | 81local void putShortMSB OF((deflate_state *s, uInt b)); 82local void flush_pending OF((z_streamp strm)); |
83local int read_buf OF((z_streamp strm, charf *buf, unsigned size)); | 83local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); |
84#ifdef ASMV 85 void match_init OF((void)); /* asm code initialization */ | 84#ifdef ASMV 85 void match_init OF((void)); /* asm code initialization */ |
86 uInt longest_match OF((deflate_state *s, IPos cur_match)); 87#else 88local uInt longest_match OF((deflate_state *s, IPos cur_match)); |
|
86#endif 87 88#ifdef DEBUG 89local void check_match OF((deflate_state *s, IPos start, IPos match, 90 int length)); 91#endif 92 93/* =========================================================================== --- 21 unchanged lines hidden (view full) --- 115typedef struct config_s { 116 ush good_length; /* reduce lazy search above this match length */ 117 ush max_lazy; /* do not perform lazy search above this match length */ 118 ush nice_length; /* quit search above this match length */ 119 ush max_chain; 120 compress_func func; 121} config; 122 | 89#endif 90 91#ifdef DEBUG 92local void check_match OF((deflate_state *s, IPos start, IPos match, 93 int length)); 94#endif 95 96/* =========================================================================== --- 21 unchanged lines hidden (view full) --- 118typedef struct config_s { 119 ush good_length; /* reduce lazy search above this match length */ 120 ush max_lazy; /* do not perform lazy search above this match length */ 121 ush nice_length; /* quit search above this match length */ 122 ush max_chain; 123 compress_func func; 124} config; 125 |
123local config configuration_table[10] = { | 126local const config configuration_table[10] = { |
124/* good lazy nice chain */ 125/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ 126/* 1 */ {4, 4, 8, 4, deflate_fast}, /* maximum speed, no lazy matches */ 127/* 2 */ {4, 5, 16, 8, deflate_fast}, 128/* 3 */ {4, 6, 32, 32, deflate_fast}, 129 130/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */ 131/* 5 */ {8, 16, 32, 32, deflate_slow}, --- 20 unchanged lines hidden (view full) --- 152 */ 153#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask) 154 155 156/* =========================================================================== 157 * Insert string str in the dictionary and set match_head to the previous head 158 * of the hash chain (the most recent string with same hash key). Return 159 * the previous length of the hash chain. | 127/* good lazy nice chain */ 128/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ 129/* 1 */ {4, 4, 8, 4, deflate_fast}, /* maximum speed, no lazy matches */ 130/* 2 */ {4, 5, 16, 8, deflate_fast}, 131/* 3 */ {4, 6, 32, 32, deflate_fast}, 132 133/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */ 134/* 5 */ {8, 16, 32, 32, deflate_slow}, --- 20 unchanged lines hidden (view full) --- 155 */ 156#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask) 157 158 159/* =========================================================================== 160 * Insert string str in the dictionary and set match_head to the previous head 161 * of the hash chain (the most recent string with same hash key). Return 162 * the previous length of the hash chain. |
163 * If this file is compiled with -DFASTEST, the compression level is forced 164 * to 1, and no hash chains are maintained. |
|
160 * IN assertion: all calls to to INSERT_STRING are made with consecutive 161 * input characters and the first MIN_MATCH bytes of str are valid 162 * (except for the last MIN_MATCH-1 bytes of the input file). 163 */ | 165 * IN assertion: all calls to to INSERT_STRING are made with consecutive 166 * input characters and the first MIN_MATCH bytes of str are valid 167 * (except for the last MIN_MATCH-1 bytes of the input file). 168 */ |
169#ifdef FASTEST |
|
164#define INSERT_STRING(s, str, match_head) \ 165 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ | 170#define INSERT_STRING(s, str, match_head) \ 171 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ |
172 match_head = s->head[s->ins_h], \ 173 s->head[s->ins_h] = (Pos)(str)) 174#else 175#define INSERT_STRING(s, str, match_head) \ 176 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ |
|
166 s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \ 167 s->head[s->ins_h] = (Pos)(str)) | 177 s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \ 178 s->head[s->ins_h] = (Pos)(str)) |
179#endif |
|
168 169/* =========================================================================== 170 * Initialize the hash table (avoiding 64K overflow for 16 bit systems). 171 * prev[] will be initialized on the fly. 172 */ 173#define CLEAR_HASH(s) \ 174 s->head[s->hash_size-1] = NIL; \ | 180 181/* =========================================================================== 182 * Initialize the hash table (avoiding 64K overflow for 16 bit systems). 183 * prev[] will be initialized on the fly. 184 */ 185#define CLEAR_HASH(s) \ 186 s->head[s->hash_size-1] = NIL; \ |
175 zmemzero((charf *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); | 187 zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); |
176 177/* ========================================================================= */ | 188 189/* ========================================================================= */ |
178int deflateInit_(strm, level, version, stream_size) | 190int ZEXPORT deflateInit_(strm, level, version, stream_size) |
179 z_streamp strm; 180 int level; 181 const char *version; 182 int stream_size; 183{ 184 return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, 185 Z_DEFAULT_STRATEGY, version, stream_size); 186 /* To do: ignore strm->next_in if we use it as window */ 187} 188 189/* ========================================================================= */ | 191 z_streamp strm; 192 int level; 193 const char *version; 194 int stream_size; 195{ 196 return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, 197 Z_DEFAULT_STRATEGY, version, stream_size); 198 /* To do: ignore strm->next_in if we use it as window */ 199} 200 201/* ========================================================================= */ |
190int deflateInit2_(strm, level, method, windowBits, memLevel, strategy, | 202int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, |
191 version, stream_size) 192 z_streamp strm; 193 int level; 194 int method; 195 int windowBits; 196 int memLevel; 197 int strategy; 198 const char *version; 199 int stream_size; 200{ 201 deflate_state *s; 202 int noheader = 0; | 203 version, stream_size) 204 z_streamp strm; 205 int level; 206 int method; 207 int windowBits; 208 int memLevel; 209 int strategy; 210 const char *version; 211 int stream_size; 212{ 213 deflate_state *s; 214 int noheader = 0; |
215 static const char* my_version = ZLIB_VERSION; |
|
203 204 ushf *overlay; 205 /* We overlay pending_buf and d_buf+l_buf. This works since the average 206 * output size for (length,distance) codes is <= 24 bits. 207 */ 208 | 216 217 ushf *overlay; 218 /* We overlay pending_buf and d_buf+l_buf. This works since the average 219 * output size for (length,distance) codes is <= 24 bits. 220 */ 221 |
209 if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || | 222 if (version == Z_NULL || version[0] != my_version[0] || |
210 stream_size != sizeof(z_stream)) { 211 return Z_VERSION_ERROR; 212 } 213 if (strm == Z_NULL) return Z_STREAM_ERROR; 214 215 strm->msg = Z_NULL; 216 if (strm->zalloc == Z_NULL) { 217 strm->zalloc = zcalloc; 218 strm->opaque = (voidpf)0; 219 } 220 if (strm->zfree == Z_NULL) strm->zfree = zcfree; 221 222 if (level == Z_DEFAULT_COMPRESSION) level = 6; | 223 stream_size != sizeof(z_stream)) { 224 return Z_VERSION_ERROR; 225 } 226 if (strm == Z_NULL) return Z_STREAM_ERROR; 227 228 strm->msg = Z_NULL; 229 if (strm->zalloc == Z_NULL) { 230 strm->zalloc = zcalloc; 231 strm->opaque = (voidpf)0; 232 } 233 if (strm->zfree == Z_NULL) strm->zfree = zcfree; 234 235 if (level == Z_DEFAULT_COMPRESSION) level = 6; |
236#ifdef FASTEST 237 level = 1; 238#endif |
|
223 224 if (windowBits < 0) { /* undocumented feature: suppress zlib header */ 225 noheader = 1; 226 windowBits = -windowBits; 227 } 228 if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || 229 windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || 230 strategy < 0 || strategy > Z_HUFFMAN_ONLY) { --- 17 unchanged lines hidden (view full) --- 248 s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); 249 s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); 250 s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); 251 252 s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ 253 254 overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); 255 s->pending_buf = (uchf *) overlay; | 239 240 if (windowBits < 0) { /* undocumented feature: suppress zlib header */ 241 noheader = 1; 242 windowBits = -windowBits; 243 } 244 if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || 245 windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || 246 strategy < 0 || strategy > Z_HUFFMAN_ONLY) { --- 17 unchanged lines hidden (view full) --- 264 s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); 265 s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); 266 s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); 267 268 s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ 269 270 overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); 271 s->pending_buf = (uchf *) overlay; |
272 s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); |
|
256 257 if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || 258 s->pending_buf == Z_NULL) { 259 strm->msg = (char*)ERR_MSG(Z_MEM_ERROR); 260 deflateEnd (strm); 261 return Z_MEM_ERROR; 262 } 263 s->d_buf = overlay + s->lit_bufsize/sizeof(ush); 264 s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; 265 266 s->level = level; 267 s->strategy = strategy; 268 s->method = (Byte)method; 269 270 return deflateReset(strm); 271} 272 273/* ========================================================================= */ | 273 274 if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || 275 s->pending_buf == Z_NULL) { 276 strm->msg = (char*)ERR_MSG(Z_MEM_ERROR); 277 deflateEnd (strm); 278 return Z_MEM_ERROR; 279 } 280 s->d_buf = overlay + s->lit_bufsize/sizeof(ush); 281 s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; 282 283 s->level = level; 284 s->strategy = strategy; 285 s->method = (Byte)method; 286 287 return deflateReset(strm); 288} 289 290/* ========================================================================= */ |
274int deflateSetDictionary (strm, dictionary, dictLength) | 291int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) |
275 z_streamp strm; 276 const Bytef *dictionary; 277 uInt dictLength; 278{ 279 deflate_state *s; 280 uInt length = dictLength; 281 uInt n; 282 IPos hash_head = 0; 283 284 if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL || 285 strm->state->status != INIT_STATE) return Z_STREAM_ERROR; 286 287 s = strm->state; 288 strm->adler = adler32(strm->adler, dictionary, dictLength); 289 290 if (length < MIN_MATCH) return Z_OK; 291 if (length > MAX_DIST(s)) { 292 length = MAX_DIST(s); | 292 z_streamp strm; 293 const Bytef *dictionary; 294 uInt dictLength; 295{ 296 deflate_state *s; 297 uInt length = dictLength; 298 uInt n; 299 IPos hash_head = 0; 300 301 if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL || 302 strm->state->status != INIT_STATE) return Z_STREAM_ERROR; 303 304 s = strm->state; 305 strm->adler = adler32(strm->adler, dictionary, dictLength); 306 307 if (length < MIN_MATCH) return Z_OK; 308 if (length > MAX_DIST(s)) { 309 length = MAX_DIST(s); |
293 dictionary += dictLength - length; | 310#ifndef USE_DICT_HEAD 311 dictionary += dictLength - length; /* use the tail of the dictionary */ 312#endif |
294 } | 313 } |
295 zmemcpy((charf *)s->window, dictionary, length); | 314 zmemcpy(s->window, dictionary, length); |
296 s->strstart = length; 297 s->block_start = (long)length; 298 299 /* Insert all strings in the hash table (except for the last two bytes). 300 * s->lookahead stays null, so s->ins_h will be recomputed at the next 301 * call of fill_window. 302 */ 303 s->ins_h = s->window[0]; 304 UPDATE_HASH(s, s->ins_h, s->window[1]); 305 for (n = 0; n <= length - MIN_MATCH; n++) { 306 INSERT_STRING(s, n, hash_head); 307 } 308 if (hash_head) hash_head = 0; /* to make compiler happy */ 309 return Z_OK; 310} 311 312/* ========================================================================= */ | 315 s->strstart = length; 316 s->block_start = (long)length; 317 318 /* Insert all strings in the hash table (except for the last two bytes). 319 * s->lookahead stays null, so s->ins_h will be recomputed at the next 320 * call of fill_window. 321 */ 322 s->ins_h = s->window[0]; 323 UPDATE_HASH(s, s->ins_h, s->window[1]); 324 for (n = 0; n <= length - MIN_MATCH; n++) { 325 INSERT_STRING(s, n, hash_head); 326 } 327 if (hash_head) hash_head = 0; /* to make compiler happy */ 328 return Z_OK; 329} 330 331/* ========================================================================= */ |
313int deflateReset (strm) | 332int ZEXPORT deflateReset (strm) |
314 z_streamp strm; 315{ 316 deflate_state *s; 317 318 if (strm == Z_NULL || strm->state == Z_NULL || 319 strm->zalloc == Z_NULL || strm->zfree == Z_NULL) return Z_STREAM_ERROR; 320 321 strm->total_in = strm->total_out = 0; --- 13 unchanged lines hidden (view full) --- 335 336 _tr_init(s); 337 lm_init(s); 338 339 return Z_OK; 340} 341 342/* ========================================================================= */ | 333 z_streamp strm; 334{ 335 deflate_state *s; 336 337 if (strm == Z_NULL || strm->state == Z_NULL || 338 strm->zalloc == Z_NULL || strm->zfree == Z_NULL) return Z_STREAM_ERROR; 339 340 strm->total_in = strm->total_out = 0; --- 13 unchanged lines hidden (view full) --- 354 355 _tr_init(s); 356 lm_init(s); 357 358 return Z_OK; 359} 360 361/* ========================================================================= */ |
343int deflateParams(strm, level, strategy) | 362int ZEXPORT deflateParams(strm, level, strategy) |
344 z_streamp strm; 345 int level; 346 int strategy; 347{ 348 deflate_state *s; 349 compress_func func; 350 int err = Z_OK; 351 --- 57 unchanged lines hidden (view full) --- 409 strm->avail_out -= len; 410 strm->state->pending -= len; 411 if (strm->state->pending == 0) { 412 strm->state->pending_out = strm->state->pending_buf; 413 } 414} 415 416/* ========================================================================= */ | 363 z_streamp strm; 364 int level; 365 int strategy; 366{ 367 deflate_state *s; 368 compress_func func; 369 int err = Z_OK; 370 --- 57 unchanged lines hidden (view full) --- 428 strm->avail_out -= len; 429 strm->state->pending -= len; 430 if (strm->state->pending == 0) { 431 strm->state->pending_out = strm->state->pending_buf; 432 } 433} 434 435/* ========================================================================= */ |
417int deflate (strm, flush) | 436int ZEXPORT deflate (strm, flush) |
418 z_streamp strm; 419 int flush; 420{ 421 int old_flush; /* value of flush param for previous deflate call */ 422 deflate_state *s; 423 424 if (strm == Z_NULL || strm->state == Z_NULL || 425 flush > Z_FINISH || flush < 0) { --- 117 unchanged lines hidden (view full) --- 543 /* If avail_out is zero, the application will call deflate again 544 * to flush the rest. 545 */ 546 s->noheader = -1; /* write the trailer only once! */ 547 return s->pending != 0 ? Z_OK : Z_STREAM_END; 548} 549 550/* ========================================================================= */ | 437 z_streamp strm; 438 int flush; 439{ 440 int old_flush; /* value of flush param for previous deflate call */ 441 deflate_state *s; 442 443 if (strm == Z_NULL || strm->state == Z_NULL || 444 flush > Z_FINISH || flush < 0) { --- 117 unchanged lines hidden (view full) --- 562 /* If avail_out is zero, the application will call deflate again 563 * to flush the rest. 564 */ 565 s->noheader = -1; /* write the trailer only once! */ 566 return s->pending != 0 ? Z_OK : Z_STREAM_END; 567} 568 569/* ========================================================================= */ |
551int deflateEnd (strm) | 570int ZEXPORT deflateEnd (strm) |
552 z_streamp strm; 553{ 554 int status; 555 556 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 557 | 571 z_streamp strm; 572{ 573 int status; 574 575 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; 576 |
577 status = strm->state->status; 578 if (status != INIT_STATE && status != BUSY_STATE && 579 status != FINISH_STATE) { 580 return Z_STREAM_ERROR; 581 } 582 |
|
558 /* Deallocate in reverse order of allocations: */ 559 TRY_FREE(strm, strm->state->pending_buf); 560 TRY_FREE(strm, strm->state->head); 561 TRY_FREE(strm, strm->state->prev); 562 TRY_FREE(strm, strm->state->window); 563 | 583 /* Deallocate in reverse order of allocations: */ 584 TRY_FREE(strm, strm->state->pending_buf); 585 TRY_FREE(strm, strm->state->head); 586 TRY_FREE(strm, strm->state->prev); 587 TRY_FREE(strm, strm->state->window); 588 |
564 status = strm->state->status; | |
565 ZFREE(strm, strm->state); 566 strm->state = Z_NULL; 567 568 return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; 569} 570 | 589 ZFREE(strm, strm->state); 590 strm->state = Z_NULL; 591 592 return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; 593} 594 |
571/* ========================================================================= */ 572int deflateCopy (dest, source) | 595/* ========================================================================= 596 * Copy the source state to the destination state. 597 * To simplify the source, this is not supported for 16-bit MSDOS (which 598 * doesn't have enough memory anyway to duplicate compression states). 599 */ 600int ZEXPORT deflateCopy (dest, source) |
573 z_streamp dest; 574 z_streamp source; 575{ | 601 z_streamp dest; 602 z_streamp source; 603{ |
576 if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) { | 604#ifdef MAXSEG_64K 605 return Z_STREAM_ERROR; 606#else 607 deflate_state *ds; 608 deflate_state *ss; 609 ushf *overlay; 610 611 ss = source->state; 612 613 if (source == Z_NULL || dest == Z_NULL || ss == Z_NULL) { |
577 return Z_STREAM_ERROR; 578 } 579 *dest = *source; | 614 return Z_STREAM_ERROR; 615 } 616 *dest = *source; |
580 return Z_STREAM_ERROR; /* to be implemented */ 581#if 0 582 dest->state = (struct internal_state FAR *) 583 (*dest->zalloc)(1, sizeof(deflate_state)); 584 if (dest->state == Z_NULL) return Z_MEM_ERROR; | |
585 | 617 |
586 *(dest->state) = *(source->state); | 618 ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); 619 if (ds == Z_NULL) return Z_MEM_ERROR; 620 dest->state = (struct internal_state FAR *) ds; 621 *ds = *ss; 622 ds->strm = dest; 623 624 ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); 625 ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); 626 ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); 627 overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2); 628 ds->pending_buf = (uchf *) overlay; 629 630 if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || 631 ds->pending_buf == Z_NULL) { 632 deflateEnd (dest); 633 return Z_MEM_ERROR; 634 } 635 /* following zmemcpy do not work for 16-bit MSDOS */ 636 zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); 637 zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos)); 638 zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos)); 639 zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); 640 641 ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); 642 ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); 643 ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; 644 645 ds->l_desc.dyn_tree = ds->dyn_ltree; 646 ds->d_desc.dyn_tree = ds->dyn_dtree; 647 ds->bl_desc.dyn_tree = ds->bl_tree; 648 |
587 return Z_OK; 588#endif 589} 590 591/* =========================================================================== 592 * Read a new buffer from the current input stream, update the adler32 593 * and total number of bytes read. All deflate() input goes through 594 * this function so some applications may wish to modify it to avoid 595 * allocating a large strm->next_in buffer and copying from it. 596 * (See also flush_pending()). 597 */ 598local int read_buf(strm, buf, size) 599 z_streamp strm; | 649 return Z_OK; 650#endif 651} 652 653/* =========================================================================== 654 * Read a new buffer from the current input stream, update the adler32 655 * and total number of bytes read. All deflate() input goes through 656 * this function so some applications may wish to modify it to avoid 657 * allocating a large strm->next_in buffer and copying from it. 658 * (See also flush_pending()). 659 */ 660local int read_buf(strm, buf, size) 661 z_streamp strm; |
600 charf *buf; | 662 Bytef *buf; |
601 unsigned size; 602{ 603 unsigned len = strm->avail_in; 604 605 if (len > size) len = size; 606 if (len == 0) return 0; 607 608 strm->avail_in -= len; --- 44 unchanged lines hidden (view full) --- 653 * IN assertions: cur_match is the head of the hash chain for the current 654 * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 655 * OUT assertion: the match length is not greater than s->lookahead. 656 */ 657#ifndef ASMV 658/* For 80x86 and 680x0, an optimized version will be provided in match.asm or 659 * match.S. The code will be functionally equivalent. 660 */ | 663 unsigned size; 664{ 665 unsigned len = strm->avail_in; 666 667 if (len > size) len = size; 668 if (len == 0) return 0; 669 670 strm->avail_in -= len; --- 44 unchanged lines hidden (view full) --- 715 * IN assertions: cur_match is the head of the hash chain for the current 716 * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 717 * OUT assertion: the match length is not greater than s->lookahead. 718 */ 719#ifndef ASMV 720/* For 80x86 and 680x0, an optimized version will be provided in match.asm or 721 * match.S. The code will be functionally equivalent. 722 */ |
723#ifndef FASTEST |
|
661local uInt longest_match(s, cur_match) 662 deflate_state *s; 663 IPos cur_match; /* current match */ 664{ 665 unsigned chain_length = s->max_chain_length;/* max hash chain length */ 666 register Bytef *scan = s->window + s->strstart; /* current string */ 667 register Bytef *match; /* matched string */ 668 register int len; /* length of current match */ --- 118 unchanged lines hidden (view full) --- 787#else 788 scan_end1 = scan[best_len-1]; 789 scan_end = scan[best_len]; 790#endif 791 } 792 } while ((cur_match = prev[cur_match & wmask]) > limit 793 && --chain_length != 0); 794 | 724local uInt longest_match(s, cur_match) 725 deflate_state *s; 726 IPos cur_match; /* current match */ 727{ 728 unsigned chain_length = s->max_chain_length;/* max hash chain length */ 729 register Bytef *scan = s->window + s->strstart; /* current string */ 730 register Bytef *match; /* matched string */ 731 register int len; /* length of current match */ --- 118 unchanged lines hidden (view full) --- 850#else 851 scan_end1 = scan[best_len-1]; 852 scan_end = scan[best_len]; 853#endif 854 } 855 } while ((cur_match = prev[cur_match & wmask]) > limit 856 && --chain_length != 0); 857 |
795 if ((uInt)best_len <= s->lookahead) return best_len; | 858 if ((uInt)best_len <= s->lookahead) return (uInt)best_len; |
796 return s->lookahead; 797} | 859 return s->lookahead; 860} |
861 862#else /* FASTEST */ 863/* --------------------------------------------------------------------------- 864 * Optimized version for level == 1 only 865 */ 866local uInt longest_match(s, cur_match) 867 deflate_state *s; 868 IPos cur_match; /* current match */ 869{ 870 register Bytef *scan = s->window + s->strstart; /* current string */ 871 register Bytef *match; /* matched string */ 872 register int len; /* length of current match */ 873 register Bytef *strend = s->window + s->strstart + MAX_MATCH; 874 875 /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. 876 * It is easy to get rid of this optimization if necessary. 877 */ 878 Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); 879 880 Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); 881 882 Assert(cur_match < s->strstart, "no future"); 883 884 match = s->window + cur_match; 885 886 /* Return failure if the match length is less than 2: 887 */ 888 if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1; 889 890 /* The check at best_len-1 can be removed because it will be made 891 * again later. (This heuristic is not always a win.) 892 * It is not necessary to compare scan[2] and match[2] since they 893 * are always equal when the other bytes match, given that 894 * the hash keys are equal and that HASH_BITS >= 8. 895 */ 896 scan += 2, match += 2; 897 Assert(*scan == *match, "match[2]?"); 898 899 /* We check for insufficient lookahead only every 8th comparison; 900 * the 256th check will be made at strstart+258. 901 */ 902 do { 903 } while (*++scan == *++match && *++scan == *++match && 904 *++scan == *++match && *++scan == *++match && 905 *++scan == *++match && *++scan == *++match && 906 *++scan == *++match && *++scan == *++match && 907 scan < strend); 908 909 Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); 910 911 len = MAX_MATCH - (int)(strend - scan); 912 913 if (len < MIN_MATCH) return MIN_MATCH - 1; 914 915 s->match_start = cur_match; 916 return len <= s->lookahead ? len : s->lookahead; 917} 918#endif /* FASTEST */ |
|
798#endif /* ASMV */ 799 800#ifdef DEBUG 801/* =========================================================================== 802 * Check that the match at match_start is indeed a match. 803 */ 804local void check_match(s, start, match, length) 805 deflate_state *s; 806 IPos start, match; 807 int length; 808{ 809 /* check that the match is indeed a match */ | 919#endif /* ASMV */ 920 921#ifdef DEBUG 922/* =========================================================================== 923 * Check that the match at match_start is indeed a match. 924 */ 925local void check_match(s, start, match, length) 926 deflate_state *s; 927 IPos start, match; 928 int length; 929{ 930 /* check that the match is indeed a match */ |
810 if (zmemcmp((charf *)s->window + match, 811 (charf *)s->window + start, length) != EQUAL) { | 931 if (zmemcmp(s->window + match, 932 s->window + start, length) != EQUAL) { |
812 fprintf(stderr, " start %u, match %u, length %d\n", 813 start, match, length); 814 do { 815 fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); 816 } while (--length != 0); 817 z_error("invalid match"); 818 } | 933 fprintf(stderr, " start %u, match %u, length %d\n", 934 start, match, length); 935 do { 936 fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); 937 } while (--length != 0); 938 z_error("invalid match"); 939 } |
819 if (verbose > 1) { | 940 if (z_verbose > 1) { |
820 fprintf(stderr,"\\[%d,%d]", start-match, length); 821 do { putc(s->window[start++], stderr); } while (--length != 0); 822 } 823} 824#else 825# define check_match(s, start, match, length) 826#endif 827 --- 28 unchanged lines hidden (view full) --- 856 */ 857 more--; 858 859 /* If the window is almost full and there is insufficient lookahead, 860 * move the upper half to the lower one to make room in the upper half. 861 */ 862 } else if (s->strstart >= wsize+MAX_DIST(s)) { 863 | 941 fprintf(stderr,"\\[%d,%d]", start-match, length); 942 do { putc(s->window[start++], stderr); } while (--length != 0); 943 } 944} 945#else 946# define check_match(s, start, match, length) 947#endif 948 --- 28 unchanged lines hidden (view full) --- 977 */ 978 more--; 979 980 /* If the window is almost full and there is insufficient lookahead, 981 * move the upper half to the lower one to make room in the upper half. 982 */ 983 } else if (s->strstart >= wsize+MAX_DIST(s)) { 984 |
864 zmemcpy((charf *)s->window, (charf *)s->window+wsize, 865 (unsigned)wsize); | 985 zmemcpy(s->window, s->window+wsize, (unsigned)wsize); |
866 s->match_start -= wsize; 867 s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ | 986 s->match_start -= wsize; 987 s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ |
868 | |
869 s->block_start -= (long) wsize; 870 871 /* Slide the hash table (could be avoided with 32 bit values | 988 s->block_start -= (long) wsize; 989 990 /* Slide the hash table (could be avoided with 32 bit values |
872 at the expense of memory usage): | 991 at the expense of memory usage). We slide even when level == 0 992 to keep the hash table consistent if we switch back to level > 0 993 later. (Using level 0 permanently is not an optimal usage of 994 zlib, so we don't care about this pathological case.) |
873 */ | 995 */ |
874 n = s->hash_size; 875 p = &s->head[n]; 876 do { 877 m = *--p; 878 *p = (Pos)(m >= wsize ? m-wsize : NIL); 879 } while (--n); | 996 n = s->hash_size; 997 p = &s->head[n]; 998 do { 999 m = *--p; 1000 *p = (Pos)(m >= wsize ? m-wsize : NIL); 1001 } while (--n); |
880 | 1002 |
881 n = wsize; 882 p = &s->prev[n]; 883 do { 884 m = *--p; 885 *p = (Pos)(m >= wsize ? m-wsize : NIL); 886 /* If n is not on any hash chain, prev[n] is garbage but 887 * its value will never be used. 888 */ 889 } while (--n); 890 | 1003 n = wsize; 1004#ifndef FASTEST 1005 p = &s->prev[n]; 1006 do { 1007 m = *--p; 1008 *p = (Pos)(m >= wsize ? m-wsize : NIL); 1009 /* If n is not on any hash chain, prev[n] is garbage but 1010 * its value will never be used. 1011 */ 1012 } while (--n); 1013#endif |
891 more += wsize; 892 } 893 if (s->strm->avail_in == 0) return; 894 895 /* If there was no sliding: 896 * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && 897 * more == window_size - lookahead - strstart 898 * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) 899 * => more >= window_size - 2*WSIZE + 2 900 * In the BIG_MEM or MMAP case (not yet supported), 901 * window_size == input_size + MIN_LOOKAHEAD && 902 * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. 903 * Otherwise, window_size == 2*WSIZE so more >= 2. 904 * If there was sliding, more >= WSIZE. So in all cases, more >= 2. 905 */ 906 Assert(more >= 2, "more < 2"); 907 | 1014 more += wsize; 1015 } 1016 if (s->strm->avail_in == 0) return; 1017 1018 /* If there was no sliding: 1019 * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && 1020 * more == window_size - lookahead - strstart 1021 * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) 1022 * => more >= window_size - 2*WSIZE + 2 1023 * In the BIG_MEM or MMAP case (not yet supported), 1024 * window_size == input_size + MIN_LOOKAHEAD && 1025 * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. 1026 * Otherwise, window_size == 2*WSIZE so more >= 2. 1027 * If there was sliding, more >= WSIZE. So in all cases, more >= 2. 1028 */ 1029 Assert(more >= 2, "more < 2"); 1030 |
908 n = read_buf(s->strm, (charf *)s->window + s->strstart + s->lookahead, 909 more); | 1031 n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); |
910 s->lookahead += n; 911 912 /* Initialize the hash value now that we have some input: */ 913 if (s->lookahead >= MIN_MATCH) { 914 s->ins_h = s->window[s->strstart]; 915 UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); 916#if MIN_MATCH != 3 917 Call UPDATE_HASH() MIN_MATCH-3 more times --- 28 unchanged lines hidden (view full) --- 946} 947 948/* =========================================================================== 949 * Copy without compression as much as possible from the input stream, return 950 * the current block state. 951 * This function does not insert new strings in the dictionary since 952 * uncompressible data is probably not useful. This function is used 953 * only for the level=0 compression option. | 1032 s->lookahead += n; 1033 1034 /* Initialize the hash value now that we have some input: */ 1035 if (s->lookahead >= MIN_MATCH) { 1036 s->ins_h = s->window[s->strstart]; 1037 UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); 1038#if MIN_MATCH != 3 1039 Call UPDATE_HASH() MIN_MATCH-3 more times --- 28 unchanged lines hidden (view full) --- 1068} 1069 1070/* =========================================================================== 1071 * Copy without compression as much as possible from the input stream, return 1072 * the current block state. 1073 * This function does not insert new strings in the dictionary since 1074 * uncompressible data is probably not useful. This function is used 1075 * only for the level=0 compression option. |
954 * NOTE: this function should be optimized to avoid extra copying. | 1076 * NOTE: this function should be optimized to avoid extra copying from 1077 * window to pending_buf. |
955 */ 956local block_state deflate_stored(s, flush) 957 deflate_state *s; 958 int flush; 959{ | 1078 */ 1079local block_state deflate_stored(s, flush) 1080 deflate_state *s; 1081 int flush; 1082{ |
1083 /* Stored blocks are limited to 0xffff bytes, pending_buf is limited 1084 * to pending_buf_size, and each stored block has a 5 byte header: 1085 */ 1086 ulg max_block_size = 0xffff; 1087 ulg max_start; 1088 1089 if (max_block_size > s->pending_buf_size - 5) { 1090 max_block_size = s->pending_buf_size - 5; 1091 } 1092 1093 /* Copy as much as possible from input to output: */ |
|
960 for (;;) { 961 /* Fill the window as much as possible: */ 962 if (s->lookahead <= 1) { 963 964 Assert(s->strstart < s->w_size+MAX_DIST(s) || 965 s->block_start >= (long)s->w_size, "slide too late"); 966 967 fill_window(s); 968 if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; 969 970 if (s->lookahead == 0) break; /* flush the current block */ 971 } 972 Assert(s->block_start >= 0L, "block gone"); 973 974 s->strstart += s->lookahead; 975 s->lookahead = 0; 976 | 1094 for (;;) { 1095 /* Fill the window as much as possible: */ 1096 if (s->lookahead <= 1) { 1097 1098 Assert(s->strstart < s->w_size+MAX_DIST(s) || 1099 s->block_start >= (long)s->w_size, "slide too late"); 1100 1101 fill_window(s); 1102 if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; 1103 1104 if (s->lookahead == 0) break; /* flush the current block */ 1105 } 1106 Assert(s->block_start >= 0L, "block gone"); 1107 1108 s->strstart += s->lookahead; 1109 s->lookahead = 0; 1110 |
977 /* Stored blocks are limited to 0xffff bytes: */ 978 if (s->strstart == 0 || s->strstart > 0xfffe) { | 1111 /* Emit a stored block if pending_buf will be full: */ 1112 max_start = s->block_start + max_block_size; 1113 if (s->strstart == 0 || (ulg)s->strstart >= max_start) { |
979 /* strstart == 0 is possible when wraparound on 16-bit machine */ | 1114 /* strstart == 0 is possible when wraparound on 16-bit machine */ |
980 s->lookahead = s->strstart - 0xffff; 981 s->strstart = 0xffff; | 1115 s->lookahead = (uInt)(s->strstart - max_start); 1116 s->strstart = (uInt)max_start; 1117 FLUSH_BLOCK(s, 0); |
982 } | 1118 } |
983 984 /* Emit a stored block if it is large enough: */ | 1119 /* Flush if we may have to slide, otherwise block_start may become 1120 * negative and the data will be gone: 1121 */ |
985 if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { 986 FLUSH_BLOCK(s, 0); 987 } 988 } 989 FLUSH_BLOCK(s, flush == Z_FINISH); 990 return flush == Z_FINISH ? finish_done : block_done; 991} 992 --- 43 unchanged lines hidden (view full) --- 1036 if (s->strategy != Z_HUFFMAN_ONLY) { 1037 s->match_length = longest_match (s, hash_head); 1038 } 1039 /* longest_match() sets match_start */ 1040 } 1041 if (s->match_length >= MIN_MATCH) { 1042 check_match(s, s->strstart, s->match_start, s->match_length); 1043 | 1122 if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { 1123 FLUSH_BLOCK(s, 0); 1124 } 1125 } 1126 FLUSH_BLOCK(s, flush == Z_FINISH); 1127 return flush == Z_FINISH ? finish_done : block_done; 1128} 1129 --- 43 unchanged lines hidden (view full) --- 1173 if (s->strategy != Z_HUFFMAN_ONLY) { 1174 s->match_length = longest_match (s, hash_head); 1175 } 1176 /* longest_match() sets match_start */ 1177 } 1178 if (s->match_length >= MIN_MATCH) { 1179 check_match(s, s->strstart, s->match_start, s->match_length); 1180 |
1044 bflush = _tr_tally(s, s->strstart - s->match_start, 1045 s->match_length - MIN_MATCH); | 1181 _tr_tally_dist(s, s->strstart - s->match_start, 1182 s->match_length - MIN_MATCH, bflush); |
1046 1047 s->lookahead -= s->match_length; 1048 1049 /* Insert new strings in the hash table only if the match length 1050 * is not too large. This saves time but degrades compression. 1051 */ | 1183 1184 s->lookahead -= s->match_length; 1185 1186 /* Insert new strings in the hash table only if the match length 1187 * is not too large. This saves time but degrades compression. 1188 */ |
1189#ifndef FASTEST |
|
1052 if (s->match_length <= s->max_insert_length && 1053 s->lookahead >= MIN_MATCH) { 1054 s->match_length--; /* string at strstart already in hash table */ 1055 do { 1056 s->strstart++; 1057 INSERT_STRING(s, s->strstart, hash_head); 1058 /* strstart never exceeds WSIZE-MAX_MATCH, so there are 1059 * always MIN_MATCH bytes ahead. 1060 */ 1061 } while (--s->match_length != 0); 1062 s->strstart++; | 1190 if (s->match_length <= s->max_insert_length && 1191 s->lookahead >= MIN_MATCH) { 1192 s->match_length--; /* string at strstart already in hash table */ 1193 do { 1194 s->strstart++; 1195 INSERT_STRING(s, s->strstart, hash_head); 1196 /* strstart never exceeds WSIZE-MAX_MATCH, so there are 1197 * always MIN_MATCH bytes ahead. 1198 */ 1199 } while (--s->match_length != 0); 1200 s->strstart++; |
1063 } else { | 1201 } else 1202#endif 1203 { |
1064 s->strstart += s->match_length; 1065 s->match_length = 0; 1066 s->ins_h = s->window[s->strstart]; 1067 UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); 1068#if MIN_MATCH != 3 1069 Call UPDATE_HASH() MIN_MATCH-3 more times 1070#endif 1071 /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not 1072 * matter since it will be recomputed at next deflate call. 1073 */ 1074 } 1075 } else { 1076 /* No match, output a literal byte */ 1077 Tracevv((stderr,"%c", s->window[s->strstart])); | 1204 s->strstart += s->match_length; 1205 s->match_length = 0; 1206 s->ins_h = s->window[s->strstart]; 1207 UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); 1208#if MIN_MATCH != 3 1209 Call UPDATE_HASH() MIN_MATCH-3 more times 1210#endif 1211 /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not 1212 * matter since it will be recomputed at next deflate call. 1213 */ 1214 } 1215 } else { 1216 /* No match, output a literal byte */ 1217 Tracevv((stderr,"%c", s->window[s->strstart])); |
1078 bflush = _tr_tally (s, 0, s->window[s->strstart]); | 1218 _tr_tally_lit (s, s->window[s->strstart], bflush); |
1079 s->lookahead--; 1080 s->strstart++; 1081 } 1082 if (bflush) FLUSH_BLOCK(s, 0); 1083 } 1084 FLUSH_BLOCK(s, flush == Z_FINISH); 1085 return flush == Z_FINISH ? finish_done : block_done; 1086} --- 62 unchanged lines hidden (view full) --- 1149 * match is not better, output the previous match: 1150 */ 1151 if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { 1152 uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; 1153 /* Do not insert strings in hash table beyond this. */ 1154 1155 check_match(s, s->strstart-1, s->prev_match, s->prev_length); 1156 | 1219 s->lookahead--; 1220 s->strstart++; 1221 } 1222 if (bflush) FLUSH_BLOCK(s, 0); 1223 } 1224 FLUSH_BLOCK(s, flush == Z_FINISH); 1225 return flush == Z_FINISH ? finish_done : block_done; 1226} --- 62 unchanged lines hidden (view full) --- 1289 * match is not better, output the previous match: 1290 */ 1291 if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { 1292 uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; 1293 /* Do not insert strings in hash table beyond this. */ 1294 1295 check_match(s, s->strstart-1, s->prev_match, s->prev_length); 1296 |
1157 bflush = _tr_tally(s, s->strstart -1 - s->prev_match, 1158 s->prev_length - MIN_MATCH); | 1297 _tr_tally_dist(s, s->strstart -1 - s->prev_match, 1298 s->prev_length - MIN_MATCH, bflush); |
1159 1160 /* Insert in hash table all strings up to the end of the match. 1161 * strstart-1 and strstart are already inserted. If there is not 1162 * enough lookahead, the last two strings are not inserted in 1163 * the hash table. 1164 */ 1165 s->lookahead -= s->prev_length-1; 1166 s->prev_length -= 2; --- 9 unchanged lines hidden (view full) --- 1176 if (bflush) FLUSH_BLOCK(s, 0); 1177 1178 } else if (s->match_available) { 1179 /* If there was no match at the previous position, output a 1180 * single literal. If there was a match but the current match 1181 * is longer, truncate the previous match to a single literal. 1182 */ 1183 Tracevv((stderr,"%c", s->window[s->strstart-1])); | 1299 1300 /* Insert in hash table all strings up to the end of the match. 1301 * strstart-1 and strstart are already inserted. If there is not 1302 * enough lookahead, the last two strings are not inserted in 1303 * the hash table. 1304 */ 1305 s->lookahead -= s->prev_length-1; 1306 s->prev_length -= 2; --- 9 unchanged lines hidden (view full) --- 1316 if (bflush) FLUSH_BLOCK(s, 0); 1317 1318 } else if (s->match_available) { 1319 /* If there was no match at the previous position, output a 1320 * single literal. If there was a match but the current match 1321 * is longer, truncate the previous match to a single literal. 1322 */ 1323 Tracevv((stderr,"%c", s->window[s->strstart-1])); |
1184 if (_tr_tally (s, 0, s->window[s->strstart-1])) { | 1324 _tr_tally_lit(s, s->window[s->strstart-1], bflush); 1325 if (bflush) { |
1185 FLUSH_BLOCK_ONLY(s, 0); 1186 } 1187 s->strstart++; 1188 s->lookahead--; 1189 if (s->strm->avail_out == 0) return need_more; 1190 } else { 1191 /* There is no previous match to compare with, wait for 1192 * the next step to decide. 1193 */ 1194 s->match_available = 1; 1195 s->strstart++; 1196 s->lookahead--; 1197 } 1198 } 1199 Assert (flush != Z_NO_FLUSH, "no flush?"); 1200 if (s->match_available) { 1201 Tracevv((stderr,"%c", s->window[s->strstart-1])); | 1326 FLUSH_BLOCK_ONLY(s, 0); 1327 } 1328 s->strstart++; 1329 s->lookahead--; 1330 if (s->strm->avail_out == 0) return need_more; 1331 } else { 1332 /* There is no previous match to compare with, wait for 1333 * the next step to decide. 1334 */ 1335 s->match_available = 1; 1336 s->strstart++; 1337 s->lookahead--; 1338 } 1339 } 1340 Assert (flush != Z_NO_FLUSH, "no flush?"); 1341 if (s->match_available) { 1342 Tracevv((stderr,"%c", s->window[s->strstart-1])); |
1202 _tr_tally (s, 0, s->window[s->strstart-1]); | 1343 _tr_tally_lit(s, s->window[s->strstart-1], bflush); |
1203 s->match_available = 0; 1204 } 1205 FLUSH_BLOCK(s, flush == Z_FINISH); 1206 return flush == Z_FINISH ? finish_done : block_done; 1207} | 1344 s->match_available = 0; 1345 } 1346 FLUSH_BLOCK(s, flush == Z_FINISH); 1347 return flush == Z_FINISH ? finish_done : block_done; 1348} |