]>
git.saurik.com Git - wxWidgets.git/blob - src/zlib/inffast.c
0e41957fef11d73b5f2b636efc4c5c59b26e5af4
1 /* inffast.c -- process literals and length/distance pairs fast
2 * Copyright (C) 1995-2002 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
13 struct inflate_codes_state
{int dummy
;}; /* for buggy compilers */
15 /* simplify the use of the inflate_huft type with some defines */
16 #define exop word.what.Exop
17 #define bits word.what.Bits
19 /* macros for bit input with no checking and for returning unused bytes */
20 #define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}
21 #define UNGRAB {c=z->avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;}
23 /* Called with number of bytes left to write in window at least 258
24 (the maximum string length) and number of input bytes available
25 at least ten. The ten bytes are six bytes for the longest length/
26 distance pair plus four bytes for overloading the bit buffer. */
28 #if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */
29 int inflate_fast(uInt bl
, uInt bd
, inflate_huft
* tl
, inflate_huft
* td
, inflate_blocks_statef
* s
, z_streamp z
)
31 int inflate_fast(bl
, bd
, tl
, td
, s
, z
)
34 inflate_huft
*td
; /* need separate declaration for Borland C++ */
35 inflate_blocks_statef
*s
;
39 inflate_huft
*t
; /* temporary pointer */
40 uInt e
; /* extra bits or operation */
41 uLong b
; /* bit buffer */
42 uInt k
; /* bits in bit buffer */
43 Bytef
*p
; /* input data pointer */
44 uInt n
; /* bytes available there */
45 Bytef
*q
; /* output window write pointer */
46 uInt m
; /* bytes to end of window or read pointer */
47 uInt ml
; /* mask for literal/length tree */
48 uInt md
; /* mask for distance tree */
49 uInt c
; /* bytes to copy */
50 uInt d
; /* distance back to copy from */
51 Bytef
*r
; /* copy source pointer */
53 /* load input, output, bit values */
56 /* initialize masks */
57 ml
= inflate_mask
[bl
];
58 md
= inflate_mask
[bd
];
60 /* do until not enough input or output space for fast loop */
61 do { /* assume called with m >= 258 && n >= 10 */
62 /* get literal/length code */
63 GRABBITS(20) /* max bits for literal/length code */
64 if ((e
= (t
= tl
+ ((uInt
)b
& ml
))->exop
) == 0)
67 Tracevv((stderr
, t
->base
>= 0x20 && t
->base
< 0x7f ?
68 "inflate: * literal '%c'\n" :
69 "inflate: * literal 0x%02x\n", t
->base
));
78 /* get extra bits for length */
80 c
= t
->base
+ ((uInt
)b
& inflate_mask
[e
]);
82 Tracevv((stderr
, "inflate: * length %u\n", c
));
84 /* decode distance base of block to copy */
85 GRABBITS(15); /* max bits for distance code */
86 e
= (t
= td
+ ((uInt
)b
& md
))->exop
;
91 /* get extra bits to add to distance base */
93 GRABBITS(e
) /* get extra bits (up to 13) */
94 d
= t
->base
+ ((uInt
)b
& inflate_mask
[e
]);
96 Tracevv((stderr
, "inflate: * distance %u\n", d
));
101 if (r
< s
->window
) /* wrap if needed */
104 r
+= s
->end
- s
->window
; /* force pointer in window */
105 } while (r
< s
->window
); /* covers invalid distances */
109 c
-= e
; /* wrapped copy */
118 else /* normal copy */
127 else /* normal copy */
137 else if ((e
& 64) == 0)
140 e
= (t
+= ((uInt
)b
& inflate_mask
[e
]))->exop
;
144 z
->msg
= (char*)"invalid distance code";
155 if ((e
= (t
+= ((uInt
)b
& inflate_mask
[e
]))->exop
) == 0)
158 Tracevv((stderr
, t
->base
>= 0x20 && t
->base
< 0x7f ?
159 "inflate: * literal '%c'\n" :
160 "inflate: * literal 0x%02x\n", t
->base
));
161 *q
++ = (Byte
)t
->base
;
168 Tracevv((stderr
, "inflate: * end of block\n"));
175 z
->msg
= (char*)"invalid literal/length code";
181 } while (m
>= 258 && n
>= 10);
183 /* not enough input or output--restore pointers and return */