Zlib: Use defines for inffast
Zlib's inffast uses a handful of magic numbers. It would be easier to
read and maintain if these magic numbers were instead #defines.
NigelTao@ wrote this code to clean up the magic numbers in
https://chromium-review.googlesource.com/c/chromium/src/+/601694
Nigel gave me permission to make a separate pull request to separate out
just the magic number cleaning.
BUG=764431
Change-Id: I0a62e31e98d4f3afcc64bd096e62a4b4b175644b
Reviewed-on: https://chromium-review.googlesource.com/663424
Commit-Queue: Chris Blume <cblume@google.com>
Reviewed-by: Adenilson Cavalcanti <cavalcantii@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#502982}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 5d7c2b78db0e96c769dee8d4ed3a9aeac8ef21d5
diff --git a/inffast.c b/inffast.c
index 0dbd1db..66c0d02 100644
--- a/inffast.c
+++ b/inffast.c
@@ -23,8 +23,8 @@
Entry assumptions:
state->mode == LEN
- strm->avail_in >= 6
- strm->avail_out >= 258
+ strm->avail_in >= INFLATE_FAST_MIN_HAVE
+ strm->avail_out >= INFLATE_FAST_MIN_LEFT
start >= strm->avail_out
state->bits < 8
@@ -80,10 +80,10 @@
/* copy state to local variables */
state = (struct inflate_state FAR *)strm->state;
in = strm->next_in;
- last = in + (strm->avail_in - 5);
+ last = in + (strm->avail_in - (INFLATE_FAST_MIN_HAVE - 1));
out = strm->next_out;
beg = out - (start - strm->avail_out);
- end = out + (strm->avail_out - 257);
+ end = out + (strm->avail_out - (INFLATE_FAST_MIN_LEFT - 1));
#ifdef INFLATE_STRICT
dmax = state->dmax;
#endif
@@ -298,9 +298,12 @@
/* update state and return */
strm->next_in = in;
strm->next_out = out;
- strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
+ strm->avail_in = (unsigned)(in < last ?
+ (INFLATE_FAST_MIN_HAVE - 1) + (last - in) :
+ (INFLATE_FAST_MIN_HAVE - 1) - (in - last));
strm->avail_out = (unsigned)(out < end ?
- 257 + (end - out) : 257 - (out - end));
+ (INFLATE_FAST_MIN_LEFT - 1) + (end - out) :
+ (INFLATE_FAST_MIN_LEFT - 1) - (out - end));
state->hold = hold;
state->bits = bits;
return;