Java Code Examples for io.netty.util.internal.PlatformDependent#isUnaligned()

The following examples show how to use io.netty.util.internal.PlatformDependent#isUnaligned() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ByteUtil.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public static boolean equals(final byte[] left,
                             final byte[] right,
                             final int rightOffset,
                             final int rightLength) {
   if (left == right)
      return true;
   if (left == null || right == null)
      return false;
   if (left.length != rightLength)
      return false;
   if (PlatformDependent.isUnaligned() && PlatformDependent.hasUnsafe()) {
      return equalsUnsafe(left, right, rightOffset, rightLength);
   } else {
      return equalsSafe(left, right, rightOffset, rightLength);
   }
}
 
Example 2
Source File: ByteUtil.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Returns {@code true} if  the {@link SimpleString} encoded content into {@code bytes} is equals to {@code s},
 * {@code false} otherwise.
 * <p>
 * It assumes that the {@code bytes} content is read using {@link SimpleString#readSimpleString(ByteBuf, int)} ie starting right after the
 * length field.
 */
public static boolean equals(final byte[] bytes, final ByteBuf byteBuf, final int offset, final int length) {
   if (bytes.length != length)
      return false;
   if (PlatformDependent.isUnaligned() && PlatformDependent.hasUnsafe()) {
      if ((offset + length) > byteBuf.writerIndex()) {
         throw new IndexOutOfBoundsException();
      }
      if (byteBuf.hasArray()) {
         return equals(bytes, byteBuf.array(), byteBuf.arrayOffset() + offset, length);
      } else if (byteBuf.hasMemoryAddress()) {
         return equalsOffHeap(bytes, byteBuf.memoryAddress(), offset, length);
      }
   }
   return equalsOnHeap(bytes, byteBuf, offset, length);
}
 
Example 3
Source File: UnpooledUnsafeHeapByteBuf.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
@Deprecated
protected SwappedByteBuf newSwappedByteBuf() {
    if (PlatformDependent.isUnaligned()) {
        // Only use if unaligned access is supported otherwise there is no gain.仅在支持非对齐访问时使用,否则没有增益。
        return new UnsafeHeapSwappedByteBuf(this);
    }
    return super.newSwappedByteBuf();
}
 
Example 4
Source File: PooledUnsafeDirectByteBuf.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
protected SwappedByteBuf newSwappedByteBuf() {
    if (PlatformDependent.isUnaligned()) {
        // Only use if unaligned access is supported otherwise there is no gain.仅在支持非对齐访问时使用,否则没有增益。
        return new UnsafeDirectSwappedByteBuf(this);
    }
    return super.newSwappedByteBuf();
}
 
Example 5
Source File: PooledUnsafeHeapByteBuf.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
@Deprecated
protected SwappedByteBuf newSwappedByteBuf() {
    if (PlatformDependent.isUnaligned()) {
        // Only use if unaligned access is supported otherwise there is no gain.仅在支持非对齐访问时使用,否则没有增益。
        return new UnsafeHeapSwappedByteBuf(this);
    }
    return super.newSwappedByteBuf();
}
 
Example 6
Source File: UnpooledUnsafeDirectByteBuf.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
protected SwappedByteBuf newSwappedByteBuf() {
    if (PlatformDependent.isUnaligned()) {
        // Only use if unaligned access is supported otherwise there is no gain.仅在支持非对齐访问时使用,否则没有增益。
        return new UnsafeDirectSwappedByteBuf(this);
    }
    return super.newSwappedByteBuf();
}
 
Example 7
Source File: AbstractByteBufPool.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Batch hash code implementation that works at its best if {@code bytes}
 * contains a {@link org.apache.activemq.artemis.api.core.SimpleString} encoded.
 */
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);
}