richardstartin / xxhash-benchmark

https://richardstartin.github.io/posts/xxhash
1 stars 0 forks source link

Incorrect unsafe implementation (possibly related with issue #1) #2

Closed curioustorvald closed 4 years ago

curioustorvald commented 4 years ago

To retrieve correct data from an array using Unsafe, you need to add the array base offset to the objects' own offset, producing code similar to this:

protected int getInt(byte[] array, int offset) {
    return UnsafeWrapper.getInt(array, offset + UNSAFE.arrayBaseOffset(array)); // notice the additional 'UNSAFE.arrayBaseOffset'
}

I'm leaving an issue here rather than a pull request as I'm not in a situation to run a test, thanks.

richardstartin commented 4 years ago

The usage is correct. The array base offset is added in UnsafeWrapper (here).