Skip to content

Commit dae668d

Browse files
committed
Reorder variables in inflate functions to reduce padding holes
due to variable alignment requirements.
1 parent 1ec47b7 commit dae668d

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

inffast_tpl.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ void Z_INTERNAL INFLATE_FAST(PREFIX3(stream) *strm, uint32_t start) {
5959
unsigned char *beg; /* inflate()'s initial strm->next_out */
6060
unsigned char *end; /* while out < end, enough space available */
6161
unsigned char *safe; /* can use chunkcopy provided out < safe */
62+
unsigned char *window; /* allocated sliding window, if wsize != 0 */
6263
unsigned wsize; /* window size or zero if not using window */
6364
unsigned whave; /* valid bytes in the window */
6465
unsigned wnext; /* window write index */
65-
unsigned char *window; /* allocated sliding window, if wsize != 0 */
6666

6767
/* hold is a local copy of strm->hold. By default, hold satisfies the same
6868
invariants that strm->hold does, namely that (hold >> bits) == 0. This
@@ -101,18 +101,18 @@ void Z_INTERNAL INFLATE_FAST(PREFIX3(stream) *strm, uint32_t start) {
101101
with (1<<bits)-1 to drop those excess bits so that, on function exit, we
102102
keep the invariant that (state->hold >> state->bits) == 0.
103103
*/
104-
uint64_t hold; /* local strm->hold */
105104
unsigned bits; /* local strm->bits */
106-
code const *lcode; /* local strm->lencode */
107-
code const *dcode; /* local strm->distcode */
105+
uint64_t hold; /* local strm->hold */
108106
unsigned lmask; /* mask for first level of length codes */
109107
unsigned dmask; /* mask for first level of distance codes */
108+
code const *lcode; /* local strm->lencode */
109+
code const *dcode; /* local strm->distcode */
110110
const code *here; /* retrieved table entry */
111111
unsigned op; /* code bits, operation, extra bits, or */
112112
/* window position, window bytes to copy */
113113
unsigned len; /* match length, unused bytes */
114-
unsigned dist; /* match distance */
115114
unsigned char *from; /* where to copy match from */
115+
unsigned dist; /* match distance */
116116
unsigned extra_safe; /* copy chunks safely in all cases */
117117

118118
/* copy state to local variables */

inflate.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ Z_INTERNAL void free_inflate(PREFIX3(stream) *strm) {
217217
* This function is hidden in ZLIB_COMPAT builds.
218218
*/
219219
int32_t ZNG_CONDEXPORT PREFIX(inflateInit2)(PREFIX3(stream) *strm, int32_t windowBits) {
220-
int32_t ret;
221220
struct inflate_state *state;
221+
int32_t ret;
222222

223223
/* Initialize functable */
224224
FUNCTABLE_INIT;
@@ -477,12 +477,12 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
477477
struct inflate_state *state;
478478
const unsigned char *next; /* next input */
479479
unsigned char *put; /* next output */
480+
unsigned char *from; /* where to copy match bytes from */
480481
unsigned have, left; /* available input and output */
481482
uint32_t hold; /* bit buffer */
482483
unsigned bits; /* bits in bit buffer */
483484
uint32_t in, out; /* save starting available input and output */
484485
unsigned copy; /* number of stored or match bytes to copy */
485-
unsigned char *from; /* where to copy match bytes from */
486486
code here; /* current decoding table entry */
487487
code last; /* parent table entry */
488488
unsigned len; /* length to copy for repeats, bits to drop */
@@ -1306,11 +1306,11 @@ static uint32_t syncsearch(uint32_t *have, const uint8_t *buf, uint32_t len) {
13061306
}
13071307

13081308
int32_t Z_EXPORT PREFIX(inflateSync)(PREFIX3(stream) *strm) {
1309+
struct inflate_state *state;
1310+
size_t in, out; /* temporary to save total_in and total_out */
13091311
unsigned len; /* number of bytes to look at or looked at */
13101312
int flags; /* temporary to save header status */
1311-
size_t in, out; /* temporary to save total_in and total_out */
13121313
unsigned char buf[4]; /* to restore bit buffer to byte string */
1313-
struct inflate_state *state;
13141314

13151315
/* check parameters */
13161316
if (inflateStateCheck(strm))

0 commit comments

Comments
 (0)