some more cleanup and performance squeezing

This commit is contained in:
Arndt 2016-08-26 08:40:52 +02:00
parent 12d8cae46f
commit 686d693103
9 changed files with 145 additions and 78 deletions

View file

@ -1,6 +1,6 @@
package btools.util;
public final class ByteArrayUnifier
public final class ByteArrayUnifier implements IByteArrayUnifier
{
private byte[][] byteArrayCache;
private int[] crcCrosscheck;

View file

@ -107,18 +107,44 @@ public class ByteDataReader
return ( v & 1 ) == 0 ? v >> 1 : -(v >> 1 );
}
public final int readVarLengthUnsigned_old()
{
int v = 0;
int shift = 0;
for ( ;; )
{
byte b = ab[aboffset++];
v |= ( ( b & 0x7f ) << shift );
if ( ( b & 0x80 ) == 0 )
{
break;
}
shift += 7;
}
return v;
}
public final int readVarLengthUnsigned()
{
int v = 0;
int shift = 0;
for(;;)
{
int i7 = ab[aboffset++] & 0xff;
v |= (( i7 & 0x7f ) << shift);
if ( ( i7 & 0x80 ) == 0 ) break;
shift += 7;
}
return v;
byte b;
int v = (b=ab[aboffset++]) & 0x7f;
if ( b >= 0 ) return v;
v |= ( (b=ab[aboffset++]) & 0x7f ) << 7;
if ( b >= 0 ) return v;
v |= ( (b=ab[aboffset++]) & 0x7f ) << 14;
if ( b >= 0 ) return v;
v |= ( (b=ab[aboffset++]) & 0x7f ) << 21;
if ( b >= 0 ) return v;
v |= ( (b=ab[aboffset++]) & 0x7f ) << 28;
if ( b >= 0 ) return v;
v |= ( (b=ab[aboffset++]) & 0x7f ) << 35;
if ( b >= 0 ) return v;
v |= ( (b=ab[aboffset++]) & 0x7f ) << 42;
if ( b >= 0 ) return v;
v |= ( (b=ab[aboffset++]) & 0x7f ) << 49;
if ( b >= 0 ) return v;
v |= ( (b=ab[aboffset++]) & 0x7f ) << 56;
return v;
}
public final void readFully( byte[] ta )

View file

@ -5,20 +5,8 @@ package btools.util;
*
* @author ab
*/
public class Crc32
public final class Crc32
{
public static int crc( long bitmap )
{
int crc = 0xFFFFFFFF;
long bm = bitmap;
for( int j=0; j<8; j++ )
{
crc = (crc >>> 8) ^ crctable[(crc ^ (int)bm) & 0xff];
bm >>= 8;
}
return crc;
}
public static int crc( byte[] ab, int offset, int len )
{
int crc = 0xFFFFFFFF;
@ -30,17 +18,6 @@ public class Crc32
return crc;
}
public static int crcWithInverseBit( byte[] ab, boolean isInverse )
{
int crc = 0xFFFFFF ^ ( isInverse ? 0x990951ba : 0x706af48f ); // inverse is webbed into crc...
int end = ab.length;
for( int j=0; j<end; j++ )
{
crc = (crc >>> 8) ^ crctable[(crc ^ ab[j]) & 0xff];
}
return isInverse ? crc | 0x80000000 : crc & 0x7fffffff; // ... and set as high bit
}
private static int[] crctable = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,

View file

@ -0,0 +1,6 @@
package btools.util;
public interface IByteArrayUnifier
{
byte[] unify( byte[] ab, int offset, int len );
}