Skip to content

Commit

Permalink
feat(s3stream): optimization on crc calculation (#596)
Browse files Browse the repository at this point in the history
Signed-off-by: Shichao Nie <[email protected]>
  • Loading branch information
SCNieh authored Nov 8, 2023
1 parent 960631c commit e4e79a8
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import io.netty.buffer.ByteBuf;

import java.nio.ByteBuffer;
import java.util.zip.CRC32;

public class WALUtil {
Expand All @@ -41,11 +42,10 @@ public static int crc32(ByteBuf buf) {
*/
public static int crc32(ByteBuf buf, int length) {
CRC32 crc32 = new CRC32();
buf.markReaderIndex();
for (int i = 0; i < length; i++) {
crc32.update(buf.readByte());
ByteBuf slice = buf.slice(buf.readerIndex(), length);
for (ByteBuffer buffer : slice.nioBuffers()) {
crc32.update(buffer);
}
buf.resetReaderIndex();
return (int) (crc32.getValue() & 0x7FFFFFFF);
}

Expand Down

0 comments on commit e4e79a8

Please sign in to comment.