Unsafe: efficiently comparing two byte arrays

Paul Sandoz paul.sandoz at oracle.com
Thu Feb 27 15:05:06 UTC 2014

On Feb 27, 2014, at 3:52 PM, Andrew Haley <aph at redhat.com> wrote:

> Hi,
> On 02/26/2014 03:42 PM, Paul Sandoz wrote:
>> A common reason why Unsafe is used is to more efficiently compare two unsigned byte arrays, viewing those byte arrays as long arrays.
> Why not simply provide ByteBuffer.forArray(byte[]) ?  Then we'd have all the
> ByteBuffer intrinsics for put() and get() operations.

Good point, even if it does require the creation of two ByteBuffer instances.

An implementation of Arrays.compare could do that if things were suitably intrinsified, which i am not sure is the case as of today.

I will do some measurements and report back.


More information about the core-libs-dev mailing list