Harry Potter
unread,Jun 12, 2020, 4:16:28 PM6/12/20You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Hi! I have an issue. I am working on compression, and the code is way too slow. :( I need help optimizing my code. A code snippet follows:
-----------------------
static unsigned char po_getnumlits2 (int pos)
{
register unsigned char i, j, l=0;
unsigned char* tmpcptr=&InBuffer[pos];
for (i=1; i<=100; ++i) {
--tmpcptr;
if (pos-i<0) break;
//l=1;
for (j=i-1; j>0; --j) {
if (tmpcptr[0]==tmpcptr[j])
{--l; break;}
} ++l;
} return l>100?100:l;
}
static unsigned char po_getnum (int in, unsigned char len)
{
unsigned i, j, k, l, l2;
unsigned x;
unsigned char comp=0;
unsigned char* y;
if (j<0) {po_compl=EstimDist (k, po_getnumlits(in))+1; po_offs[0]=k; return 1;}
po_offs[0]=-1;
return 0;
}
for (i=j=k=0; i<len; ++i) {
j=0; y=&InBuffer[in+i];
for (k=0; k<100 && j<100; /*++k*/) {
if (len<6 && j>=32) {j=100; break;}
m=0;
--y;
if ((unsigned)y<(unsigned)&InBuffer) {j= 100; break;}
if (cin[i]==*y) break;
if (j>=0) {
for (l=1;l<=j; ++l) {
if (*y==y[l]) {
m=1; break;
}
}
}
if (m) {++j; continue;}
++j;
++k;
}
if (k<100 && j<100) {
po_offs[i]=k; //comp+=/*5-(k<4)*/(k<6?1:getnumbits(po_getnumlits(vz.InPos-buflen+i+1)));
if (0 && 1 || len>=3 && len<4) comp+=(k<8?4:EstimDist(k-8, po_getnumlits2(l2)-8))+(0 && buflen>=4)+1; //n=1;
else if (len<6) comp+=EstimDist(k, po_getnumlits(in+i));
else comp+=EstimDist (k, po_getnumlits2(in+i)); continue;
}
else {
po_offs[i]=-1;
if ((len<5)) x=po_writelit (in+i, InBuffer[in+i], &l);
else x=po_writelit1a (in+i, InBuffer[in+i], &l);
comp+=GetHuffLen (&cin[i], 1);
po_nl1[i]=x; po_nl2[i]=l;
}
}
po_compl=comp;
return 1;
}
static unsigned po_writelit1a (int pos, unsigned char c, unsigned *outlen)
{
register unsigned i, k, l, m;
register unsigned j;
register unsigned char* s=&InBuffer[pos];
memset (&litsused, 0, sizeof(litsused));
for (i=1; i<=100; ++i) {
if (pos-i<0) break;
--s;
litsused[*s]=1;
}
if (pos) {
k=InBuffer[pos-1];
} else k=0;
for (j=i=l=0; j<256; ++j) {
if (!litsused[j&255] && HuffEnv.entrynum[j]>=0) {
if ((j&255)<c) i++;
l++;
}
}
*outlen=(unsigned) l;
return i;
}
-------------------------
I'm compiling on a Win10/64 laptop with an Intel Celeron N2830 microprocessor using DMC.