Skip to content

Commit 5ec92ea

Browse files
npt-1707dpiparo
authored andcommitted
Use post-increment only in inffast.c.
(cherry picked from commit 80a81f6)
1 parent aad8497 commit 5ec92ea

1 file changed

Lines changed: 31 additions & 50 deletions

File tree

builtins/zlib/inffast.c

Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,6 @@
1010

1111
#ifndef ASMINF
1212

13-
/* Allow machine dependent optimization for post-increment or pre-increment.
14-
Based on testing to date,
15-
Pre-increment preferred for:
16-
- PowerPC G3 (Adler)
17-
- MIPS R5000 (Randers-Pehrson)
18-
Post-increment preferred for:
19-
- none
20-
No measurable difference:
21-
- Pentium III (Anderson)
22-
- M68060 (Nikl)
23-
*/
24-
#ifdef POSTINC
25-
# define OFF 0
26-
# define PUP(a) *(a)++
27-
#else
28-
# define OFF 1
29-
# define PUP(a) *++(a)
30-
#endif
31-
3213
/*
3314
Decode literal, length, and distance codes and write out the resulting
3415
literal and match bytes until either not enough input or output is
@@ -94,9 +75,9 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* infla
9475

9576
/* copy state to local variables */
9677
state = (struct inflate_state FAR *)strm->state;
97-
in = strm->next_in - OFF;
78+
in = strm->next_in;
9879
last = in + (strm->avail_in - 5);
99-
out = strm->next_out - OFF;
80+
out = strm->next_out;
10081
beg = out - (start - strm->avail_out);
10182
end = out + (strm->avail_out - 257);
10283
#ifdef INFLATE_STRICT
@@ -117,9 +98,9 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* infla
11798
input data or output space */
11899
do {
119100
if (bits < 15) {
120-
hold += (unsigned long)(PUP(in)) << bits;
101+
hold += (unsigned long)(*in++) << bits;
121102
bits += 8;
122-
hold += (unsigned long)(PUP(in)) << bits;
103+
hold += (unsigned long)(*in++) << bits;
123104
bits += 8;
124105
}
125106
here = lcode[hold & lmask];
@@ -132,14 +113,14 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* infla
132113
Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
133114
"inflate: literal '%c'\n" :
134115
"inflate: literal 0x%02x\n", here.val));
135-
PUP(out) = (unsigned char)(here.val);
116+
*out++ = (unsigned char)(here.val);
136117
}
137118
else if (op & 16) { /* length base */
138119
len = (unsigned)(here.val);
139120
op &= 15; /* number of extra bits */
140121
if (op) {
141122
if (bits < op) {
142-
hold += (unsigned long)(PUP(in)) << bits;
123+
hold += (unsigned long)(*in++) << bits;
143124
bits += 8;
144125
}
145126
len += (unsigned)hold & ((1U << op) - 1);
@@ -148,9 +129,9 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* infla
148129
}
149130
Tracevv((stderr, "inflate: length %u\n", len));
150131
if (bits < 15) {
151-
hold += (unsigned long)(PUP(in)) << bits;
132+
hold += (unsigned long)(*in++) << bits;
152133
bits += 8;
153-
hold += (unsigned long)(PUP(in)) << bits;
134+
hold += (unsigned long)(*in++) << bits;
154135
bits += 8;
155136
}
156137
here = dcode[hold & dmask];
@@ -163,10 +144,10 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* infla
163144
dist = (unsigned)(here.val);
164145
op &= 15; /* number of extra bits */
165146
if (bits < op) {
166-
hold += (unsigned long)(PUP(in)) << bits;
147+
hold += (unsigned long)(*in++) << bits;
167148
bits += 8;
168149
if (bits < op) {
169-
hold += (unsigned long)(PUP(in)) << bits;
150+
hold += (unsigned long)(*in++) << bits;
170151
bits += 8;
171152
}
172153
}
@@ -194,30 +175,30 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* infla
194175
#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
195176
if (len <= op - whave) {
196177
do {
197-
PUP(out) = 0;
178+
*out++ = 0;
198179
} while (--len);
199180
continue;
200181
}
201182
len -= op - whave;
202183
do {
203-
PUP(out) = 0;
184+
*out++ = 0;
204185
} while (--op > whave);
205186
if (op == 0) {
206187
from = out - dist;
207188
do {
208-
PUP(out) = PUP(from);
189+
*out++ = *from++;
209190
} while (--len);
210191
continue;
211192
}
212193
#endif
213194
}
214-
from = window - OFF;
195+
from = window;
215196
if (wnext == 0) { /* very common case */
216197
from += wsize - op;
217198
if (op < len) { /* some from window */
218199
len -= op;
219200
do {
220-
PUP(out) = PUP(from);
201+
*out++ = *from++;
221202
} while (--op);
222203
from = out - dist; /* rest from output */
223204
}
@@ -228,14 +209,14 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* infla
228209
if (op < len) { /* some from end of window */
229210
len -= op;
230211
do {
231-
PUP(out) = PUP(from);
212+
*out++ = *from++;
232213
} while (--op);
233-
from = window - OFF;
214+
from = window;
234215
if (wnext < len) { /* some from start of window */
235216
op = wnext;
236217
len -= op;
237218
do {
238-
PUP(out) = PUP(from);
219+
*out++ = *from++;
239220
} while (--op);
240221
from = out - dist; /* rest from output */
241222
}
@@ -246,35 +227,35 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* infla
246227
if (op < len) { /* some from window */
247228
len -= op;
248229
do {
249-
PUP(out) = PUP(from);
230+
*out++ = *from++;
250231
} while (--op);
251232
from = out - dist; /* rest from output */
252233
}
253234
}
254235
while (len > 2) {
255-
PUP(out) = PUP(from);
256-
PUP(out) = PUP(from);
257-
PUP(out) = PUP(from);
236+
*out++ = *from++;
237+
*out++ = *from++;
238+
*out++ = *from++;
258239
len -= 3;
259240
}
260241
if (len) {
261-
PUP(out) = PUP(from);
242+
*out++ = *from++;
262243
if (len > 1)
263-
PUP(out) = PUP(from);
244+
*out++ = *from++;
264245
}
265246
}
266247
else {
267248
from = out - dist; /* copy direct from output */
268249
do { /* minimum length is three */
269-
PUP(out) = PUP(from);
270-
PUP(out) = PUP(from);
271-
PUP(out) = PUP(from);
250+
*out++ = *from++;
251+
*out++ = *from++;
252+
*out++ = *from++;
272253
len -= 3;
273254
} while (len > 2);
274255
if (len) {
275-
PUP(out) = PUP(from);
256+
*out++ = *from++;
276257
if (len > 1)
277-
PUP(out) = PUP(from);
258+
*out++ = *from++;
278259
}
279260
}
280261
}
@@ -311,8 +292,8 @@ void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) /* infla
311292
hold &= (1U << bits) - 1;
312293

313294
/* update state and return */
314-
strm->next_in = in + OFF;
315-
strm->next_out = out + OFF;
295+
strm->next_in = in;
296+
strm->next_out = out;
316297
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
317298
strm->avail_out = (unsigned)(out < end ?
318299
257 + (end - out) : 257 - (out - end));

0 commit comments

Comments
 (0)