bzip2 mode reduced down to 36.5kb. yay.

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@1205 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
justin1014 2002-09-27 04:05:26 +00:00
parent 83655f8352
commit 4dc468b307
4 changed files with 17 additions and 24 deletions

View file

@ -125,7 +125,7 @@ typedef unsigned short UInt16;
/*-- Stuff for randomising repetitive blocks. --*/ /*-- Stuff for randomising repetitive blocks. --*/
extern Int16 BZ2_rNums[512]; // make this 513 for smaller-data mode. extern Int16 BZ2_rNums[513]; // make this 512 for bigger-data/smaller-code mode.
#define BZ_RAND_DECLS \ #define BZ_RAND_DECLS \
Int32 rNToGo; \ Int32 rNToGo; \
@ -329,7 +329,7 @@ typedef
/* for doing the final run-length decoding */ /* for doing the final run-length decoding */
UChar state_out_ch; UChar state_out_ch;
Int32 state_out_len; Int32 state_out_len;
Bool blockRandomised; Int32 blockRandomised;
BZ_RAND_DECLS; BZ_RAND_DECLS;
/* the buffer for bit stream reading */ /* the buffer for bit stream reading */

View file

@ -90,7 +90,7 @@ static int __mygetbits(int *vtmp, int nnn, DState* s)
(s->bsLive-nnn)) & ((1 << nnn)-1); (s->bsLive-nnn)) & ((1 << nnn)-1);
s->bsLive -= nnn; s->bsLive -= nnn;
*vtmp = v; *vtmp = v;
break; return 0;
} }
if (s->strm->avail_in == 0) return 1; if (s->strm->avail_in == 0) return 1;
s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in)))); s->bsBuff = (s->bsBuff << 8) | ((UInt32) (*((UChar*)(s->strm->next_in))));
@ -100,13 +100,11 @@ static int __mygetbits(int *vtmp, int nnn, DState* s)
// s->strm->total_in_lo32++; // s->strm->total_in_lo32++;
// if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; // if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++;
} }
return 0;
} }
#define GET_BITS(lll,vvv,nnn) \ #define GET_BITS(lll,vvv,nnn) \
case lll: s->state = lll; \ case lll: s->state = lll; \
{ int vtmp; if (__mygetbits(&vtmp,nnn,s)) RETURN(BZ_OK) \ if (__mygetbits(&vvv,nnn,s)) RETURN(BZ_OK)
(vvv) = vtmp; }
#define GET_UCHAR(lll,uuu) \ #define GET_UCHAR(lll,uuu) \
GET_BITS(lll,uuu,8) GET_BITS(lll,uuu,8)
@ -131,9 +129,8 @@ static int __mygetbits(int *vtmp, int nnn, DState* s)
groupPos--; \ groupPos--; \
zn = gMinlen; \ zn = gMinlen; \
GET_BITS(label1, zvec, zn); \ GET_BITS(label1, zvec, zn); \
while (1) { \ for (;;) { \
if (zn > 20 /* the longest code */) \ if (zn > 20 /* the longest code */) RETURN(BZ_DATA_ERROR); \
RETURN(BZ_DATA_ERROR); \
if (zvec <= gLimit[zn]) break; \ if (zvec <= gLimit[zn]) break; \
zn++; \ zn++; \
GET_BIT(label2, zj); \ GET_BIT(label2, zj); \
@ -149,7 +146,7 @@ static int __mygetbits(int *vtmp, int nnn, DState* s)
/*---------------------------------------------------*/ /*---------------------------------------------------*/
Int32 BZ2_decompress ( DState* s ) Int32 BZ2_decompress ( DState* s )
{ {
UChar uc; Int32 uc;
Int32 retVal; Int32 retVal;
Int32 minLen, maxLen; Int32 minLen, maxLen;
bz_stream* strm = s->strm; bz_stream* strm = s->strm;
@ -331,8 +328,7 @@ Int32 BZ2_decompress ( DState* s )
/*-- MTF init --*/ /*-- MTF init --*/
{ {
Int32 ii, jj, kk; Int32 ii, jj, kk = MTFA_SIZE-1;
kk = MTFA_SIZE-1;
for (ii = 256 / MTFL_SIZE - 1; ii >= 0; ii--) { for (ii = 256 / MTFL_SIZE - 1; ii >= 0; ii--) {
for (jj = MTFL_SIZE-1; jj >= 0; jj--) { for (jj = MTFL_SIZE-1; jj >= 0; jj--) {
s->mtfa[kk] = (UChar)(ii * MTFL_SIZE + jj); s->mtfa[kk] = (UChar)(ii * MTFL_SIZE + jj);
@ -354,13 +350,13 @@ Int32 BZ2_decompress ( DState* s )
es = -1; es = -1;
N = 1; N = 1;
do { while (nextSym == BZ_RUNA || nextSym == BZ_RUNB)
if (nextSym == BZ_RUNA) es = es + (0+1) * N; else {
if (nextSym == BZ_RUNB) es = es + (1+1) * N; if (nextSym == BZ_RUNA) es += N;
N = N * 2; N = N << 1;
if (nextSym == BZ_RUNB) es += N;
GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym); GET_MTF_VAL(BZ_X_MTF_3, BZ_X_MTF_4, nextSym);
} }
while (nextSym == BZ_RUNA || nextSym == BZ_RUNB);
es++; es++;
uc = s->seqToUnseq[ s->mtfa[s->mtfbase[0]] ]; uc = s->seqToUnseq[ s->mtfa[s->mtfbase[0]] ];
@ -397,7 +393,7 @@ Int32 BZ2_decompress ( DState* s )
/* avoid general-case expense */ /* avoid general-case expense */
pp = s->mtfbase[0]; pp = s->mtfbase[0];
uc = s->mtfa[pp+nn]; uc = s->mtfa[pp+nn];
while (nn > 3) { /*while (nn > 3) {
Int32 z = pp+nn; Int32 z = pp+nn;
s->mtfa[(z) ] = s->mtfa[(z)-1]; s->mtfa[(z) ] = s->mtfa[(z)-1];
s->mtfa[(z)-1] = s->mtfa[(z)-2]; s->mtfa[(z)-1] = s->mtfa[(z)-2];
@ -405,6 +401,7 @@ Int32 BZ2_decompress ( DState* s )
s->mtfa[(z)-3] = s->mtfa[(z)-4]; s->mtfa[(z)-3] = s->mtfa[(z)-4];
nn -= 4; nn -= 4;
} }
*/
while (nn > 0) { while (nn > 0) {
s->mtfa[(pp+nn)] = s->mtfa[(pp+nn)-1]; nn--; s->mtfa[(pp+nn)] = s->mtfa[(pp+nn)-1]; nn--;
}; };

View file

@ -65,8 +65,7 @@
// smaller data mode that saves 336 bytes of data, but adds 60 bytes of code. // smaller data mode that saves 336 bytes of data, but adds 60 bytes of code.
// currently saving code is more important to reach our targets. this may change tho. #if 1
#if 0
#define PACK3(x,y,z) ((z) << 20)|((y) << 10)|(x) #define PACK3(x,y,z) ((z) << 20)|((y) << 10)|(x)

View file

@ -13,10 +13,7 @@
#ifdef NSIS_COMPRESS_USE_BZIP2 #ifdef NSIS_COMPRESS_USE_BZIP2
#include "../bzip2/bzlib.h" #include "../bzip2/bzlib.h"
static int bz2_needreinit; static int bz2_needreinit;
// void NSISCALL genrtable(); // using this method reduces data by 336, but adds ~60 to code. void NSISCALL genrtable();
// currently it makes sense to spend the money on data and reduce code size, but that may change.
#define genrtable()
#define z_stream bz_stream #define z_stream bz_stream
#define inflateInit(x) { if (BZ2_bzDecompressInit(x)<0) return _LANG_INVALIDCRC; } #define inflateInit(x) { if (BZ2_bzDecompressInit(x)<0) return _LANG_INVALIDCRC; }