Remove memory copies when doing CRC32 processing in JdkZlibDecoder

Motivation:

We not need to do any memory copies when doing CRC32 processing.

Modifications:

Use ByteBufChecksum to eliminate memory copies.

Result:

Less memory copies.
This commit is contained in:
Norman Maurer 2016-07-19 14:32:46 +02:00
parent 2ce1d29d4d
commit 3ebbd96820

View File

@ -38,7 +38,7 @@ public class JdkZlibDecoder extends ZlibDecoder {
private final byte[] dictionary;
// GZIP related
private final CRC32 crc;
private final ByteBufChecksum crc;
private enum GzipState {
HEADER_START,
@ -91,7 +91,7 @@ public class JdkZlibDecoder extends ZlibDecoder {
switch (wrapper) {
case GZIP:
inflater = new Inflater(true);
crc = new CRC32();
crc = ByteBufChecksum.wrapChecksum(new CRC32());
break;
case NONE:
inflater = new Inflater(true);
@ -271,10 +271,8 @@ public class JdkZlibDecoder extends ZlibDecoder {
}
// mtime (int)
crc.update(in.readByte());
crc.update(in.readByte());
crc.update(in.readByte());
crc.update(in.readByte());
crc.update(in, in.readerIndex(), 4);
in.skipBytes(4);
crc.update(in.readUnsignedByte()); // extra flags
crc.update(in.readUnsignedByte()); // operating system
@ -298,9 +296,8 @@ public class JdkZlibDecoder extends ZlibDecoder {
if (in.readableBytes() < xlen) {
return false;
}
byte[] xtra = new byte[xlen];
in.readBytes(xtra);
crc.update(xtra);
crc.update(in, in.readerIndex(), xlen);
in.skipBytes(xlen);
}
gzipState = GzipState.SKIP_FNAME;
case SKIP_FNAME: