Example usage for io.netty.util.internal PlatformDependent isUnaligned

List of usage examples for io.netty.util.internal PlatformDependent isUnaligned

Introduction

In this page you can find the example usage for io.netty.util.internal PlatformDependent isUnaligned.

Prototype

public static boolean isUnaligned() 

Source Link

Document

true if and only if the platform supports unaligned access.

Usage

From source file:org.apache.activemq.artemis.utils.AbstractByteBufPool.java

License:Apache License

/**
 * Batch hash code implementation that works at its best if {@code bytes}
 * contains a {@link org.apache.activemq.artemis.api.core.SimpleString} encoded.
 *///from   w  w w.  j a  v  a 2  s  . c om
private static int hashCode(final ByteBuf bytes, final int offset, final int length) {
    if (PlatformDependent.isUnaligned() && PlatformDependent.hasUnsafe()) {
        //if the platform allows it, the hash code could be computed without bounds checking
        if (bytes.hasArray()) {
            return onHeapHashCode(bytes.array(), bytes.arrayOffset() + offset, length);
        } else if (bytes.hasMemoryAddress()) {
            return offHeapHashCode(bytes.memoryAddress(), offset, length);
        }
    }
    return byteBufHashCode(bytes, offset, length);
}