diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:08:07 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:08:07 -0700 |
commit | bdde4e09d21edff02ea5093b7f6eccbf166b272f (patch) | |
tree | a64632a98a6bea6e5df864d6e5b6f2e51ea69c1c /inffast.c | |
parent | 1c71d8b13b54f91ddec361d3053ecce26e6ff761 (diff) | |
download | zlib-bdde4e09d21edff02ea5093b7f6eccbf166b272f.tar.gz zlib-bdde4e09d21edff02ea5093b7f6eccbf166b272f.tar.bz2 zlib-bdde4e09d21edff02ea5093b7f6eccbf166b272f.zip |
zlib 0.92v0.92
Diffstat (limited to 'inffast.c')
-rw-r--r-- | inffast.c | 136 |
1 files changed, 68 insertions, 68 deletions
@@ -35,19 +35,19 @@ inflate_huft *tl, *td; | |||
35 | struct inflate_blocks_state *s; | 35 | struct inflate_blocks_state *s; |
36 | z_stream *z; | 36 | z_stream *z; |
37 | { | 37 | { |
38 | inflate_huft *t; /* temporary pointer */ | 38 | inflate_huft *t; /* temporary pointer */ |
39 | int e; /* extra bits or operation */ | 39 | int e; /* extra bits or operation */ |
40 | uLong b; /* bit buffer */ | 40 | uLong b; /* bit buffer */ |
41 | uInt k; /* bits in bit buffer */ | 41 | uInt k; /* bits in bit buffer */ |
42 | Byte *p; /* input data pointer */ | 42 | Byte *p; /* input data pointer */ |
43 | uInt n; /* bytes available there */ | 43 | uInt n; /* bytes available there */ |
44 | Byte *q; /* output window write pointer */ | 44 | Byte *q; /* output window write pointer */ |
45 | uInt m; /* bytes to end of window or read pointer */ | 45 | uInt m; /* bytes to end of window or read pointer */ |
46 | uInt ml; /* mask for literal/length tree */ | 46 | uInt ml; /* mask for literal/length tree */ |
47 | uInt md; /* mask for distance tree */ | 47 | uInt md; /* mask for distance tree */ |
48 | uInt c; /* bytes to copy */ | 48 | uInt c; /* bytes to copy */ |
49 | uInt d; /* distance back to copy from */ | 49 | uInt d; /* distance back to copy from */ |
50 | Byte *r; /* copy source pointer */ | 50 | Byte *r; /* copy source pointer */ |
51 | 51 | ||
52 | /* load input, output, bit values */ | 52 | /* load input, output, bit values */ |
53 | LOAD | 53 | LOAD |
@@ -57,40 +57,40 @@ z_stream *z; | |||
57 | md = inflate_mask[bd]; | 57 | md = inflate_mask[bd]; |
58 | 58 | ||
59 | /* do until not enough input or output space for fast loop */ | 59 | /* do until not enough input or output space for fast loop */ |
60 | do { /* assume called with m >= 258 && n >= 10 */ | 60 | do { /* assume called with m >= 258 && n >= 10 */ |
61 | /* get literal/length code */ | 61 | /* get literal/length code */ |
62 | GRABBITS(20) /* max bits for literal/length code */ | 62 | GRABBITS(20) /* max bits for literal/length code */ |
63 | if ((e = (t = tl + ((uInt)b & ml))->exop) < 0) | 63 | if ((e = (t = tl + ((uInt)b & ml))->exop) < 0) |
64 | do { | 64 | do { |
65 | if (e == -128) | 65 | if (e == -128) |
66 | { | 66 | { |
67 | z->msg = "invalid literal/length code"; | 67 | z->msg = "invalid literal/length code"; |
68 | UNGRAB | 68 | UNGRAB |
69 | UPDATE | 69 | UPDATE |
70 | return Z_DATA_ERROR; | 70 | return Z_DATA_ERROR; |
71 | } | 71 | } |
72 | DUMPBITS(t->bits) | 72 | DUMPBITS(t->bits) |
73 | e = -e; | 73 | e = -e; |
74 | if (e & 64) /* end of block */ | 74 | if (e & 64) /* end of block */ |
75 | { | 75 | { |
76 | Tracevv((stderr, "inflate: * end of block\n")); | 76 | Tracevv((stderr, "inflate: * end of block\n")); |
77 | UNGRAB | 77 | UNGRAB |
78 | UPDATE | 78 | UPDATE |
79 | return Z_STREAM_END; | 79 | return Z_STREAM_END; |
80 | } | 80 | } |
81 | } while ((e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop) < 0); | 81 | } while ((e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop) < 0); |
82 | DUMPBITS(t->bits) | 82 | DUMPBITS(t->bits) |
83 | 83 | ||
84 | /* process literal or length (end of block already trapped) */ | 84 | /* process literal or length (end of block already trapped) */ |
85 | if (e & 16) /* then it's a literal */ | 85 | if (e & 16) /* then it's a literal */ |
86 | { | 86 | { |
87 | Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? | 87 | Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? |
88 | "inflate: * literal '%c'\n" : | 88 | "inflate: * literal '%c'\n" : |
89 | "inflate: * literal 0x%02x\n", t->base)); | 89 | "inflate: * literal 0x%02x\n", t->base)); |
90 | *q++ = (Byte)t->base; | 90 | *q++ = (Byte)t->base; |
91 | m--; | 91 | m--; |
92 | } | 92 | } |
93 | else /* it's a length */ | 93 | else /* it's a length */ |
94 | { | 94 | { |
95 | /* get length of block to copy (already have extra bits) */ | 95 | /* get length of block to copy (already have extra bits) */ |
96 | c = t->base + ((uInt)b & inflate_mask[e]); | 96 | c = t->base + ((uInt)b & inflate_mask[e]); |
@@ -98,53 +98,53 @@ z_stream *z; | |||
98 | Tracevv((stderr, "inflate: * length %u\n", c)); | 98 | Tracevv((stderr, "inflate: * length %u\n", c)); |
99 | 99 | ||
100 | /* decode distance base of block to copy */ | 100 | /* decode distance base of block to copy */ |
101 | GRABBITS(15); /* max bits for distance code */ | 101 | GRABBITS(15); /* max bits for distance code */ |
102 | if ((e = (t = td + ((uInt)b & md))->exop) < 0) | 102 | if ((e = (t = td + ((uInt)b & md))->exop) < 0) |
103 | do { | 103 | do { |
104 | if (e == -128) | 104 | if (e == -128) |
105 | { | 105 | { |
106 | z->msg = "invalid distance code"; | 106 | z->msg = "invalid distance code"; |
107 | UNGRAB | 107 | UNGRAB |
108 | UPDATE | 108 | UPDATE |
109 | return Z_DATA_ERROR; | 109 | return Z_DATA_ERROR; |
110 | } | 110 | } |
111 | DUMPBITS(t->bits) | 111 | DUMPBITS(t->bits) |
112 | e = -e; | 112 | e = -e; |
113 | } while ((e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop) < 0); | 113 | } while ((e = (t = t->next + ((uInt)b & inflate_mask[e]))->exop) < 0); |
114 | DUMPBITS(t->bits) | 114 | DUMPBITS(t->bits) |
115 | 115 | ||
116 | /* get extra bits to add to distance base */ | 116 | /* get extra bits to add to distance base */ |
117 | GRABBITS((uInt)e) /* get extra bits (up to 13) */ | 117 | GRABBITS((uInt)e) /* get extra bits (up to 13) */ |
118 | d = t->base + ((uInt)b & inflate_mask[e]); | 118 | d = t->base + ((uInt)b & inflate_mask[e]); |
119 | DUMPBITS(e) | 119 | DUMPBITS(e) |
120 | Tracevv((stderr, "inflate: * distance %u\n", d)); | 120 | Tracevv((stderr, "inflate: * distance %u\n", d)); |
121 | 121 | ||
122 | /* do the copy */ | 122 | /* do the copy */ |
123 | m -= c; | 123 | m -= c; |
124 | if ((uInt)(q - s->window) >= d) /* if offset before destination, */ | 124 | if ((uInt)(q - s->window) >= d) /* if offset before destination, */ |
125 | { /* just copy */ | 125 | { /* just copy */ |
126 | r = q - d; | 126 | r = q - d; |
127 | *q++ = *r++; c--; /* minimum count is three, */ | 127 | *q++ = *r++; c--; /* minimum count is three, */ |
128 | *q++ = *r++; c--; /* so unroll loop a little */ | 128 | *q++ = *r++; c--; /* so unroll loop a little */ |
129 | do { | 129 | do { |
130 | *q++ = *r++; | 130 | *q++ = *r++; |
131 | } while (--c); | 131 | } while (--c); |
132 | } | 132 | } |
133 | else /* else offset after destination */ | 133 | else /* else offset after destination */ |
134 | { | 134 | { |
135 | e = d - (q - s->window); /* bytes from offset to end */ | 135 | e = d - (q - s->window); /* bytes from offset to end */ |
136 | r = s->end - e; /* pointer to offset */ | 136 | r = s->end - e; /* pointer to offset */ |
137 | if (c > (uInt)e) /* if source crosses, */ | 137 | if (c > (uInt)e) /* if source crosses, */ |
138 | { | 138 | { |
139 | c -= e; /* copy to end of window */ | 139 | c -= e; /* copy to end of window */ |
140 | do { | 140 | do { |
141 | *q++ = *r++; | 141 | *q++ = *r++; |
142 | } while (--e); | 142 | } while (--e); |
143 | r = s->window; /* copy rest from start of window */ | 143 | r = s->window; /* copy rest from start of window */ |
144 | } | 144 | } |
145 | do { /* copy all or what's left */ | 145 | do { /* copy all or what's left */ |
146 | *q++ = *r++; | 146 | *q++ = *r++; |
147 | } while (--c); | 147 | } while (--c); |
148 | } | 148 | } |
149 | } | 149 | } |
150 | } while (m >= 258 && n >= 10); | 150 | } while (m >= 258 && n >= 10); |