Fix ByteBufChecksum optimisation for CRC32 and Adler32 (#9242)
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.
This commit is contained in:
parent
acd13e1cf7
commit
db1e662933
@ -51,7 +51,7 @@ abstract class ByteBufChecksum implements Checksum {
|
|||||||
private static Method updateByteBuffer(Checksum checksum) {
|
private static Method updateByteBuffer(Checksum checksum) {
|
||||||
try {
|
try {
|
||||||
Method method = checksum.getClass().getDeclaredMethod("update", ByteBuffer.class);
|
Method method = checksum.getClass().getDeclaredMethod("update", ByteBuffer.class);
|
||||||
method.invoke(method, ByteBuffer.allocate(1));
|
method.invoke(checksum, ByteBuffer.allocate(1));
|
||||||
return method;
|
return method;
|
||||||
} catch (Throwable ignore) {
|
} catch (Throwable ignore) {
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user