some big size savings (removed zalloc requirement from runtime yay)

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1275 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
justin1014 2002-10-02 17:19:37 +00:00
parent 87269acd79
commit 4e6828b511
4 changed files with 69 additions and 105 deletions

View file

@ -22,10 +22,6 @@ local const char border[] = { /* Order of the bit length code lengths */
void inflateReset(z_streamp z)
{
inflate_blocks_statef *s=&z->blocks;
if (s->mode == BTREE || s->mode == DTREE)
ZFREE(z, s->sub.trees.blens);
if (s->mode == CODES)
inflate_codes_free(s->sub.decode.codes, z);
s->mode = TYPE;
s->bitk = s->bitb = 0;
s->read = s->write = s->window;
@ -86,12 +82,7 @@ int r=Z_OK;
inflate_huft *tl, *td;
inflate_trees_fixed(&bl, &bd, &tl, &td);
s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td);
if (s->sub.decode.codes == Z_NULL)
{
r = Z_MEM_ERROR;
LEAVE
}
inflate_codes_new(&s->sub.decode.t_codes,bl, bd, tl, td);
}
DUMPBITS(3)
s->mode = CODES;
@ -143,12 +134,7 @@ int r=Z_OK;
r = Z_DATA_ERROR;
LEAVE
}
t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
{
r = Z_MEM_ERROR;
LEAVE
}
// t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
DUMPBITS(14)
s->sub.trees.index = 0;
Tracev((stderr, "inflate: table sizes ok\n"));
@ -157,17 +143,16 @@ int r=Z_OK;
while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10))
{
NEEDBITS(3)
s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7;
s->sub.trees.t_blens[border[s->sub.trees.index++]] = (uInt)b & 7;
DUMPBITS(3)
}
while (s->sub.trees.index < 19)
s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
s->sub.trees.t_blens[border[s->sub.trees.index++]] = 0;
s->sub.trees.bb = 7;
t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,
t = inflate_trees_bits(s->sub.trees.t_blens, &s->sub.trees.bb,
&s->sub.trees.tb, s->hufts);
if (t != Z_OK)
{
ZFREE(z, s->sub.trees.blens);
r = t;
if (r == Z_DATA_ERROR)
s->mode = BAD;
@ -191,7 +176,7 @@ int r=Z_OK;
if (c < 16)
{
DUMPBITS(t)
s->sub.trees.blens[s->sub.trees.index++] = c;
s->sub.trees.t_blens[s->sub.trees.index++] = c;
}
else /* c == 16..18 */
{
@ -206,15 +191,13 @@ int r=Z_OK;
if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
(c == 16 && i < 1))
{
// ZFREE(z, s->sub.trees.blens);
s->mode = BAD;
// z->msg = (char*)"err";//invalid bit length repeat";
r = Z_DATA_ERROR;
LEAVE
}
c = c == 16 ? s->sub.trees.blens[i - 1] : 0;
c = c == 16 ? s->sub.trees.t_blens[i - 1] : 0;
do {
s->sub.trees.blens[i++] = c;
s->sub.trees.t_blens[i++] = c;
} while (--j);
s->sub.trees.index = i;
}
@ -223,15 +206,13 @@ int r=Z_OK;
{
uInt bl, bd;
inflate_huft *tl, *td;
inflate_codes_statef *c;
bl = 9; /* must be <= 9 for lookahead assumptions */
bd = 6; /* must be <= 9 for lookahead assumptions */
t = s->sub.trees.table;
t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
s->sub.trees.blens, &bl, &bd, &tl, &td,
s->sub.trees.t_blens, &bl, &bd, &tl, &td,
s->hufts);
ZFREE(z, s->sub.trees.blens);
if (t != Z_OK)
{
if (t == (uInt)Z_DATA_ERROR)
@ -240,12 +221,7 @@ int r=Z_OK;
LEAVE
}
Tracev((stderr, "inflate: trees ok\n"));
if ((c = inflate_codes_new(bl, bd, tl, td)) == Z_NULL)
{
r = Z_MEM_ERROR;
LEAVE
}
s->sub.decode.codes = c;
inflate_codes_new(&s->sub.decode.t_codes,bl, bd, tl, td);
}
s->mode = CODES;
case CODES:
@ -253,7 +229,6 @@ int r=Z_OK;
if ((r = inflate_codes(z, r)) != Z_STREAM_END)
return inflate_flush(z, r);
r = Z_OK;
inflate_codes_free(s->sub.decode.codes, z);
LOAD
Tracev((stderr, "inflate: codes end, %lu total out\n",
z->total_out + (q >= s->read ? q - s->read :

View file

@ -15,66 +15,19 @@
#define exop word.what.Exop
#define bits word.what.Bits
typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
START, /* x: set up for LEN */
LEN, /* i: get length/literal/eob next */
LENEXT, /* i: getting length extra (have base) */
DIST, /* i: get distance next */
DISTEXT, /* i: getting distance extra */
COPY, /* o: copying bytes in window, waiting for space */
LIT, /* o: got literal, waiting for output space */
WASH, /* o: got eob, possibly still output waiting */
END, /* x: got eob and all data flushed */
BADCODE} /* x: got error */
inflate_codes_mode;
/* inflate codes private state */
struct inflate_codes_state {
/* mode */
inflate_codes_mode mode; /* current inflate_codes mode */
/* mode dependent information */
uInt len;
union {
struct {
inflate_huft *tree; /* pointer into tree */
uInt need; /* bits needed */
} code; /* if LEN or DIST, where in tree */
uInt lit; /* if LIT, literal */
struct {
uInt get; /* bits to get for extra */
uInt dist; /* distance back to copy from */
} copy; /* if EXT or COPY, where and how much */
} sub; /* submode */
/* mode independent information */
Byte lbits; /* ltree bits decoded per branch */
Byte dbits; /* dtree bits decoder per branch */
inflate_huft *ltree; /* literal/length/eob tree */
inflate_huft *dtree; /* distance tree */
};
inflate_codes_statef *inflate_codes_new(bl, bd, tl, td)
void inflate_codes_new(c,bl, bd, tl, td)
inflate_codes_statef *c;
uInt bl, bd;
inflate_huft *tl;
inflate_huft *td; /* need separate declaration for Borland C++ */
{
inflate_codes_statef *c;
if ((c = (inflate_codes_statef *)
ZALLOC(0,1,sizeof(struct inflate_codes_state))) != Z_NULL)
{
c->mode = START;
c->lbits = (Byte)bl;
c->dbits = (Byte)bd;
c->ltree = tl;
c->dtree = td;
Tracev((stderr, "inflate: codes new\n"));
}
return c;
c->mode = START;
c->lbits = (Byte)bl;
c->dbits = (Byte)bd;
c->ltree = tl;
c->dtree = td;
}
@ -93,7 +46,7 @@ int r;
Bytef *q; /* output window write pointer */
uInt m; /* bytes to end of window or read pointer */
Bytef *f; /* pointer to copy strings from */
inflate_codes_statef *c = s->sub.decode.codes; /* codes state */
inflate_codes_statef *c = &s->sub.decode.t_codes; /* codes state */
/* copy input/output information to locals (UPDATE macro restores) */
LOAD

View file

@ -3,16 +3,10 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/
struct inflate_codes_state;
typedef struct inflate_codes_state FAR inflate_codes_statef;
extern inflate_codes_statef *inflate_codes_new OF((
uInt, uInt,
extern void inflate_codes_new OF((
inflate_codes_statef *, uInt, uInt,
inflate_huft *, inflate_huft *));
extern int inflate_codes OF((
z_streamp ,
int));
#define inflate_codes_free(z,c) ZFREE(z,c)
int));

View file

@ -52,6 +52,52 @@ extern "C" {
#ifdef EXEHEAD
typedef struct inflate_huft_s FAR inflate_huft;
typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
START, /* x: set up for LEN */
LEN, /* i: get length/literal/eob next */
LENEXT, /* i: getting length extra (have base) */
DIST, /* i: get distance next */
DISTEXT, /* i: getting distance extra */
COPY, /* o: copying bytes in window, waiting for space */
LIT, /* o: got literal, waiting for output space */
WASH, /* o: got eob, possibly still output waiting */
END, /* x: got eob and all data flushed */
BADCODE} /* x: got error */
inflate_codes_mode;
/* inflate codes private state */
struct inflate_codes_state {
/* mode */
inflate_codes_mode mode; /* current inflate_codes mode */
/* mode dependent information */
uInt len;
union {
struct {
inflate_huft *tree; /* pointer into tree */
uInt need; /* bits needed */
} code; /* if LEN or DIST, where in tree */
uInt lit; /* if LIT, literal */
struct {
uInt get; /* bits to get for extra */
uInt dist; /* distance back to copy from */
} copy; /* if EXT or COPY, where and how much */
} sub; /* submode */
/* mode independent information */
Byte lbits; /* ltree bits decoded per branch */
Byte dbits; /* dtree bits decoder per branch */
inflate_huft *ltree; /* literal/length/eob tree */
inflate_huft *dtree; /* distance tree */
};
typedef enum {
@ -67,8 +113,6 @@ extern "C" {
BAD} /* got a data error--stuck here */
inflate_block_mode;
typedef struct inflate_huft_s FAR inflate_huft;
struct inflate_huft_s {
union {
struct {
@ -82,7 +126,6 @@ struct inflate_huft_s {
#define MANY 1440
struct inflate_codes_state;
typedef struct inflate_codes_state inflate_codes_statef;
struct inflate_blocks_state {
@ -96,13 +139,12 @@ struct inflate_blocks_state {
struct {
uInt table; /* table lengths (14 bits) */
uInt index; /* index into blens (or border) */
uIntf *blens; /* bit lengths of codes */
uIntf t_blens[258+31+31]; /* bit lengths of codes */
uInt bb; /* bit length tree depth */
inflate_huft *tb; /* bit length decoding tree */
} trees; /* if DTREE, decoding info for trees */
struct {
inflate_codes_statef
*codes;
inflate_codes_statef t_codes;
} decode; /* if CODES, current state */
} sub; /* submode */
uInt last; /* true if this block is the last block */