summaryrefslogtreecommitdiff
path: root/deflate.c
diff options
context:
space:
mode:
Diffstat (limited to 'deflate.c')
-rw-r--r--deflate.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/deflate.c b/deflate.c
index 6c0cd0a..726da18 100644
--- a/deflate.c
+++ b/deflate.c
@@ -117,7 +117,7 @@ local void fill_window __P((deflate_state *s));
117local int deflate_fast __P((deflate_state *s, int flush)); 117local int deflate_fast __P((deflate_state *s, int flush));
118local int deflate_slow __P((deflate_state *s, int flush)); 118local int deflate_slow __P((deflate_state *s, int flush));
119local void lm_init __P((deflate_state *s)); 119local void lm_init __P((deflate_state *s));
120local int longest_match __P((deflate_state *s, IPos cur_match)); 120local inline int longest_match __P((deflate_state *s, IPos cur_match));
121local void putShortMSB __P((deflate_state *s, uInt b)); 121local void putShortMSB __P((deflate_state *s, uInt b));
122local void flush_pending __P((z_stream *strm)); 122local void flush_pending __P((z_stream *strm));
123local int read_buf __P((z_stream *strm, char *buf, unsigned size)); 123local int read_buf __P((z_stream *strm, char *buf, unsigned size));
@@ -354,13 +354,17 @@ int deflate (strm, flush)
354 } else { 354 } else {
355 quit = deflate_slow(strm->state, flush); 355 quit = deflate_slow(strm->state, flush);
356 } 356 }
357 if (flush == Z_FULL_FLUSH) { 357 if (flush == Z_FULL_FLUSH || flush == Z_SYNC_FLUSH) {
358 ct_stored_block(strm->state, (char*)0, 0L, 0); /* special marker */ 358 ct_stored_block(strm->state, (char*)0, 0L, 0); /* special marker */
359 flush_pending(strm); 359 flush_pending(strm);
360 CLEAR_HASH(strm->state); /* forget history */ 360 if (flush == Z_FULL_FLUSH) {
361 if (strm->avail_out == 0) return Z_OK; 361 CLEAR_HASH(strm->state); /* forget history */
362 }
363 } else if (flush == Z_PARTIAL_FLUSH) {
364 ct_align(strm->state);
365 flush_pending(strm);
362 } 366 }
363 if (quit) return Z_OK; 367 if (quit || strm->avail_out == 0) return Z_OK;
364 } 368 }
365 Assert(strm->avail_out > 0, "bug2"); 369 Assert(strm->avail_out > 0, "bug2");
366 370
@@ -447,8 +451,6 @@ local int read_buf(strm, buf, size)
447local void lm_init (s) 451local void lm_init (s)
448 deflate_state *s; 452 deflate_state *s;
449{ 453{
450 register unsigned j;
451
452 s->window_size = (ulg)2L*s->w_size; 454 s->window_size = (ulg)2L*s->w_size;
453 455
454 CLEAR_HASH(s); 456 CLEAR_HASH(s);
@@ -465,15 +467,10 @@ local void lm_init (s)
465 s->lookahead = 0; 467 s->lookahead = 0;
466 s->match_length = MIN_MATCH-1; 468 s->match_length = MIN_MATCH-1;
467 s->match_available = 0; 469 s->match_available = 0;
470 s->ins_h = 0;
468#ifdef ASMV 471#ifdef ASMV
469 match_init(); /* initialize the asm code */ 472 match_init(); /* initialize the asm code */
470#endif 473#endif
471
472 s->ins_h = 0;
473 for (j=0; j<MIN_MATCH-1; j++) UPDATE_HASH(s, s->ins_h, s->window[j]);
474 /* If lookahead < MIN_MATCH, ins_h is garbage, but this is
475 * not important since only literal bytes will be emitted.
476 */
477} 474}
478 475
479/* =========================================================================== 476/* ===========================================================================
@@ -488,7 +485,7 @@ local void lm_init (s)
488/* For 80x86 and 680x0, an optimized version will be provided in match.asm or 485/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
489 * match.S. The code will be functionally equivalent. 486 * match.S. The code will be functionally equivalent.
490 */ 487 */
491local INLINE int longest_match(s, cur_match) 488local inline int longest_match(s, cur_match)
492 deflate_state *s; 489 deflate_state *s;
493 IPos cur_match; /* current match */ 490 IPos cur_match; /* current match */
494{ 491{
@@ -730,6 +727,16 @@ local void fill_window(s)
730 more); 727 more);
731 s->lookahead += n; 728 s->lookahead += n;
732 729
730 /* Initialize the hash value now that we have some input: */
731 if (s->strstart == 0 && s->lookahead >= MIN_MATCH-1) {
732 for (n=0; n<MIN_MATCH-1; n++) {
733 UPDATE_HASH(s, s->ins_h, s->window[n]);
734 }
735 }
736 /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
737 * but this is not important since only literal bytes will be emitted.
738 */
739
733 } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); 740 } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
734} 741}
735 742