Skip to content

Commit

Permalink
Fix ByteBufChecksum optimisation for CRC32 and Adler32 (netty#9242)
Browse files Browse the repository at this point in the history
Motivation:

Because of a simple bug in ByteBufChecksum#updateByteBuffer(Checksum),
ReflectiveByteBufChecksum is never used for CRC32 and Adler32, resulting
in direct ByteBuffers being checksummed byte by byte, which is
undesriable.

Modification:

Fix ByteBufChecksum#updateByteBuffer(Checksum) method to pass the
correct argument to Method#invoke(Checksum, ByteBuffer).

Result:

ReflectiveByteBufChecksum will now be used for Adler32 and CRC32 on
Java8+ and direct ByteBuffers will no longer be checksummed on slow
byte-by-byte basis.
  • Loading branch information
iamaleksey authored and normanmaurer committed Jun 16, 2019
1 parent fa1dedc commit a29532d
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private static Method updateByteBuffer(Checksum checksum) {
if (PlatformDependent.javaVersion() >= 8) {
try {
Method method = checksum.getClass().getDeclaredMethod("update", ByteBuffer.class);
method.invoke(method, ByteBuffer.allocate(1));
method.invoke(checksum, ByteBuffer.allocate(1));
return method;
} catch (Throwable ignore) {
return null;
Expand Down

0 comments on commit a29532d

Please sign in to comment.