[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A little compression...
On May 24, 5:02 pm, Harry Potter <maspethro...@aol.com> wrote:
> It's closed source. Do I have another choice? Perhaps a general
> guide on the internet for optimizing C++ code?
Maybe this will help:
//Compares a block at loc. Cur to loc. Prev in the input buffer c.In
and returns the length.
unsigned ByteRef::ChkBlock (unsigned Cur, unsigned Prev, compbuffer
&c)
{
unsigned int i, j, k;
register unsigned char* in2=c.In;
//Get max. compare len. in j
j=Cur-Prev;
k=c.InLen-Cur; if (k<j) j=k;
if (j>65) j=65; //Max. possible ref. len. =65 bytes
for (i=0; i<j && in2[Cur+i]==in2[Prev+i]; i++);
if (i<3) i=0;
return i;
}
unsigned ByteRef::ScanRef (int pos, compbuffer &c)
{
int i; //Temp. variables
int j, k;
unsigned char *in=c.In, *cu=in+pos; //Just to speed access.
len=0; //Len.=0 for init. block.
if (c.InLen-pos<3||pos<1) return 0;
//Scan from current p0os.-1 to beginning of input.
for (i=pos-1;pos<=ByteRefDepth-2?i>=0:i>=pos-(ByteRefDepth-1); i--)
{
if (*(unsigned short*)(cu)==*(unsigned short*)(in+i) &&
//If word at current pos.=word at compare block ==,
(j=ChkBlock(pos,i, c))>len) { //and better than best,
len=j; loc=i; //make current best.
}
}
return len;
}