A special-purpose
ByteBufChecksum
implementation for use with
Lz4FrameEncoder
and
Lz4FrameDecoder
.
StreamingXXHash32.asChecksum()
has a particularly nasty implementation
of
Checksum.update(int)
that allocates a single-element byte array for
every invocation.
In addition to that, it doesn't implement an overload that accepts a
ByteBuffer
as an argument.
Combined, this means that we can't use
ReflectiveByteBufChecksum
at all,
and can't use
SlowByteBufChecksum
because of its atrocious performance
with direct byte buffers (allocating an array and making a JNI call for every byte
checksummed might be considered sub-optimal by some).
Block version of xxHash32 (
XXHash32
), however, does provide
XXHash32.hash(ByteBuffer, int)
method that is efficient and does exactly
what we need, with a caveat that we can only invoke it once before having to reset.
This, however, is fine for our purposes, given the way we use it in
Lz4FrameEncoder
and
Lz4FrameDecoder
:
reset()
, followed by one
update()
, followed by
getValue()
.