Skip to content

Commit

Permalink
Some code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
asimba committed Jun 19, 2023
1 parent 02a6158 commit 3b014fd
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 56 deletions.
14 changes: 7 additions & 7 deletions axissums
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
5e2a6182f5455d95869a16753c56079eef9775e1 ./LICENSE
09112e52227f0182675725568c005221164cd671 ./README.md
547331b6beccf7bd63231084b8fa85db7202da80 ./makefile
2906cb87285a88889df3c82dc913e8e33d42c2f1 ./bin/axis
af22ad82dcedb61d75d432bb0ab08f79e64c8125 ./bin/axis.exe
ce03803d6de51f35f512581bd9a2f37fb28b3190 ./bin/axis
1c5511f60d3557a0f54d9051eccf2e9e1b7ccece ./bin/axis.exe
ffd10c35dad3e3cedac3969b7c77153084e12e51 ./bin/axisgui.py
20bbf8559dfdc191399c4b80a07ab28fe85d1d9f ./src/archive.cc
681b5f03eff93283c4a3a2bef493bb61961d3a8e ./src/archive.h
Expand All @@ -16,7 +16,7 @@ c401f18709e9ba1200f7be24e722197147735369 ./src/axislogo.svg
ac28702e2fc0df8d7adee5d33a75d81b32fbfbd4 ./src/axisum.h
99e08b3d63bc04321940cb164ea851530a4dbd03 ./src/bnode.cc
66872236291e1a931acbd9adeeb496d18c61ddcb ./src/bnode.h
9e26559b4904d5fcdaa1522aec8bb238511cc2de ./src/build.inc
7e02245b76a07a881a8fc7e5776176034c85cac7 ./src/build.inc
4d94b873542e3d87b318cf24f2c15dd226b2434d ./src/buildinc
9f1cd4c3b54f4c7bfd6c350067a99977a86a7d32 ./src/canonicalize.cc
6d06c63018cf30c1ca1b78d6a33dde98aedfe388 ./src/canonicalize.h
Expand Down Expand Up @@ -51,8 +51,8 @@ e3b60e4feb6a99f12af95e078bbc8b7f603fba36 ./src/langdata.py
c95f3e2a22128e7e83108e5e52f735d9542598c9 ./src/makefile.mk
db1f0474200d1ff94e42a862cb8e9c637b2189dc ./src/mdirs.cc
2abbe0769065cbc81448baca09d6d30960862e06 ./src/mdirs.h
5ed9e08b1ec18e58474cf43781b3766a9fab21c4 ./src/packer.cc
dca42e09f125b18766220de7fd85c410cdc2adc0 ./src/packer.h
41d84b39cba89b7c883f0ae8e0b8a71000898f01 ./src/packer.cc
bdaa58caee968f5cf0ceb06624a3e6dcf0e94a66 ./src/packer.h
56a1e17ff2d6fbd94daabf810234c253490d870b ./src/permutation.cc
fae079803baac75cbf6154a3f536628310f7e768 ./src/permutation.h
2b830bb5a3e0e3ac02fa904a87ff1f1290398b3c ./src/random.cc
Expand All @@ -65,5 +65,5 @@ e8408d7808d4535e25ee9d55ac1e99ae350fdcb3 ./src/timebits.h
ef3526c8993eb84cb42bbd30b4b4d897aa595d56 ./src/translate.py
538872498e61b87cf08aa7265e1506648f35bde2 ./src/vars.cc
afbd6daec11670aca86a20b675e56651cf6ec33a ./src/vars.h
ebb915cbeaeb7b61c7f6d0bf8556be966216b52f ./src/version.h
98376c7c297b85d05d8c47b01ff29d1fa5c5c625 ./src/version.inc
e8b4f9995052bec607bba47315109f332229ba78 ./src/version.h
98376c7c297b85d010b8d9e29c74ed6cf6d1afe9 ./src/version.inc
Binary file modified bin/axis
Binary file not shown.
Binary file modified bin/axis.exe
Binary file not shown.
14 changes: 7 additions & 7 deletions sha1sums
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
3282ab38e455bb3d934f3ebeb826663e385427e9 *./bin/axis
d7e3782228e728d73b16fef4924faad5214bfa4f *./bin/axis.exe
d3211bc77e99c53b8c741e88c73aa027cd5d54f2 *./bin/axis
1a67b414a14eb798f34700352d746b64d9e9b6f7 *./bin/axis.exe
6d8f7d55f6243c2b43f0fb64ad22523bb271a6c8 *./bin/axisgui.py
04a02a05b856af499c7e12a4ca54b192f6ee8b1c *./LICENSE
f4b7439d3196b6ac2ecc57930853e8293736ce22 *./makefile
Expand All @@ -16,7 +16,7 @@ ab1f44390543c26b49b94eba1eb736b4cdc8702c *./src/axismain.cc
4a5d5ae6faa04225a35aa5751b290570a48809fb *./src/axisum.h
78882afd798f90d581c75347ebb9bfc1264dcd1c *./src/bnode.cc
da07eb161d5606ad1db49cd6e027b0fb095f7f30 *./src/bnode.h
c46380190cadd65dec271e04b77ba0a59b470e42 *./src/build.inc
d0944a4dd2ef98161ab9b37e997cd97526938251 *./src/build.inc
01d7ae4d64aac4aa3a7cb5a34e5dd008b95058f0 *./src/buildinc
2a4ba2232e37cde6ccf4d85c0429bdb90081a687 *./src/canonicalize.cc
d3cdb3d4423c1dc67367029ba7d6c73f3d332eee *./src/canonicalize.h
Expand Down Expand Up @@ -51,8 +51,8 @@ a948a84493f5dc355b678e79b9008d7094ff85c1 *./src/hash.h
fcfe84ba2f191ef654d5cb65a99e92947f4e8ab2 *./src/makefile.mk
c139da5ddf1c747eee44e5aafee6eb312af3e29e *./src/mdirs.cc
7e2e741f8abec81de2f5372bb36963c67365267f *./src/mdirs.h
792e77cfa59da63a1df6fcd5c4fd61ba2eed64e2 *./src/packer.cc
9e8b860a97db4bdf335da63d1e4c27254ccb727a *./src/packer.h
a90c050d31c4e21646de160b165a0d64133572e8 *./src/packer.cc
e9388d1b80ad9674d219e33c719f51a8db82946e *./src/packer.h
59f93ff4a50024bd34349b0c98d5b8f7fc8470e6 *./src/permutation.cc
69db3be840f0ce074cfd51731553ad680a8d14b7 *./src/permutation.h
d14f84cf902170ff48510ebaa4a7365b2525f8eb *./src/random.cc
Expand All @@ -65,5 +65,5 @@ d14f84cf902170ff48510ebaa4a7365b2525f8eb *./src/random.cc
55e7bb198358c358942c553bca178ad1658aa0d5 *./src/translate.py
46025207b186c68b74526686560ed72decb7d64e *./src/vars.cc
b496214fa6b932662b09dd09ab5d794359886ecd *./src/vars.h
b54ce3a192f831577a42ec6da38df1f2df28e5bf *./src/version.h
38255f1981cef709a345caa443aee40a8cabd854 *./src/version.inc
a211c363366100e73d041459fc95353a04179bd5 *./src/version.h
405043c298646585673bee7c96ea442cef584fd9 *./src/version.inc
2 changes: 1 addition & 1 deletion src/build.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BUILD_NUMBER=656
BUILD_NUMBER=657
73 changes: 34 additions & 39 deletions src/packer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ packer::packer(){
hashes=new uint16_t[0x10000];
vocindx=new vocpntr[0x10000];
frequency=new uint16_t*[256];
for(int i=0;i<5;i++) frequency[i]=new uint16_t[256];
fcs=new uint16_t[5];
for(int i=0;i<256;i++) frequency[i]=new uint16_t[256];
fcs=new uint16_t[256];
lowp=&((uint8_t *)&low)[3];
hlpp=&((uint8_t *)&hlp)[0];
flt=NULL;
Expand All @@ -35,9 +35,9 @@ packer::~packer(){
del(cntxs,LZ_CAPACITY+1,(uint8_t)0);
del(vocarea,0x10000,(uint16_t)0);
del(hashes,0x10000,(uint16_t)0);
for(int i=0;i<5;i++) del(frequency[i],256,(uint16_t)0);
for(int i=0;i<256;i++) del(frequency[i],256,(uint16_t)0);
delete[] frequency;
del(fcs,5,(uint16_t)0);
del(fcs,256,(uint16_t)0);
del(vocindx,0x10000,(vocpntr){0,0});
lowp=NULL;
hlpp=NULL;
Expand All @@ -55,7 +55,7 @@ void packer::init(){
voclast=0xfffc;
range=0xffffffff;
uint32_t i,j;
for(i=0;i<5;i++){
for(i=0;i<256;i++){
for(j=0;j<256;j++) frequency[i][j]=1;
fcs[i]=256;
};
Expand All @@ -72,6 +72,7 @@ void packer::init(){
vocarea[0xfffe]=0xfffe;
vocarea[0xffff]=0xffff;
cpos=&cbuffer[1];
scntx=0xff;
finalize=false;
}

Expand All @@ -86,56 +87,43 @@ bool packer::rbuf(void *file, uint8_t *c){
return false;
}

#define rc32_rescale()\
range*=(*f)++;\
if(!++fc){\
f=frequency[cntx];\
for(s=0;s<256;s++) fc+=(*f=((*f)>>1)|(*f&1)),f++;\
};\
fcs[cntx]=fc;\
return false;

#define rc32_shift() low<<=8;if((uint32_t)((range<<=8)+low)<low) range=~low;

bool packer::rc32_getc(void *file, uint8_t *c, uint8_t cntx){
uint16_t *f=frequency[cntx],fc=fcs[cntx];
uint32_t s=0,i;
while(hlp<low||(low^(low+range))<0x1000000||range<0x10000){
hlp<<=8;
if(rbuf(file,hlpp)) return true;
if(!rpos) return false;
low<<=8;
range<<=8;
if((uint32_t)(range+low)<low) range=~low;
rc32_shift();
};
if((i=(hlp-low)/(range/=fc))<fc){
while((s+=*f)<=i) f++;
low+=(s-*f)*range;
*c=(uint8_t)(f-frequency[cntx]);
range*=(*f)++;
if(!++fc){
f=frequency[cntx];
for(s=0;s<256;s++){
*f=((*f)>>1)|1;
fc+=*f++;
};
};
fcs[cntx]=fc;
return false;
}
else return true;
if((i=(hlp-low)/(range/=fc))>=fc) return true;
while((s+=*f)<=i) f++;
low+=(s-*f)*range;
*c=(uint8_t)(f-frequency[cntx]);
rc32_rescale();
}

bool packer::rc32_putc(void *file, uint8_t c, uint8_t cntx){
uint16_t *f=frequency[cntx],fc=fcs[cntx];
uint32_t s=0,i=c;
while((low^(low+range))<0x1000000||range<0x10000){
if(!(wbuf(file,*lowp),wpos)) return true;
low<<=8;
range<<=8;
if((uint32_t)(range+low)<low) range=~low;
rc32_shift();
};
while(i--) s+=*f++;
low+=s*(range/=fc);
range*=(*f)++;
if(!++fc){
f=frequency[cntx];
for(s=0;s<256;s++){
*f=((*f)>>1)|1;
fc+=*f++;
};
};
fcs[cntx]=fc;
return false;
rc32_rescale();
}

bool packer::packer_putc(void *file, uint8_t c){
Expand Down Expand Up @@ -191,7 +179,8 @@ bool packer::packer_putc(void *file, uint8_t c){
buf_size-=length;
}
else{
cntxs[cnt++]=4;
cntxs[cnt++]=scntx;
scntx=vocbuf[symbol];
*cbuffer|=1;
*cpos=vocbuf[symbol];
buf_size--;
Expand Down Expand Up @@ -262,7 +251,13 @@ bool packer::packer_getc(void *file, uint8_t *c){
cflags<<=1;
};
for(s=0;s<cnt;s++)
if(rc32_getc(file,cpos++,cntxs[s])) return true;
if(cntxs[s]==4){
if(rc32_getc(file,cpos,scntx)) return true;
scntx=*cpos++;
}
else{
if(rc32_getc(file,cpos++,cntxs[s])) return true;
};
cpos=&cbuffer[1];
flags=8;
};
Expand Down
1 change: 1 addition & 0 deletions src/packer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
uint8_t *hlpp;
uint8_t *cpos;
uint8_t rle_flag;
uint8_t scntx;
uint16_t *vocarea;
uint16_t *hashes;
uint16_t buf_size;
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define VERSION "0.8.31 (build 656 2023-06-03)"
#define VERSION "0.8.32 (build 657 2023-06-19)"
2 changes: 1 addition & 1 deletion src/version.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION_STRING="0.8.31"
VERSION_STRING="0.8.32"

0 comments on commit 3b014fd

Please sign in to comment.