From 5bd8b41a58be4c46bbbd5ad894df9ad9a8d1cd14 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Thu, 10 Jan 2013 18:47:21 +0900 Subject: [PATCH] Use Number.reverseBytes() instead of custom impl --- buffer/src/main/java/io/netty/buffer/ByteBufUtil.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/buffer/src/main/java/io/netty/buffer/ByteBufUtil.java b/buffer/src/main/java/io/netty/buffer/ByteBufUtil.java index efc75431be..24d043d38c 100644 --- a/buffer/src/main/java/io/netty/buffer/ByteBufUtil.java +++ b/buffer/src/main/java/io/netty/buffer/ByteBufUtil.java @@ -241,7 +241,7 @@ public final class ByteBufUtil { * Toggles the endianness of the specified 16-bit short integer. */ public static short swapShort(short value) { - return (short) (value << 8 | value >>> 8 & 0xff); + return Short.reverseBytes(value); } /** @@ -259,16 +259,14 @@ public final class ByteBufUtil { * Toggles the endianness of the specified 32-bit integer. */ public static int swapInt(int value) { - return swapShort((short) value) << 16 | - swapShort((short) (value >>> 16)) & 0xffff; + return Integer.reverseBytes(value); } /** * Toggles the endianness of the specified 64-bit long integer. */ public static long swapLong(long value) { - return (long) swapInt((int) value) << 32 | - swapInt((int) (value >>> 32)) & 0xffffffffL; + return Long.reverseBytes(value); } private static int firstIndexOf(ByteBuf buffer, int fromIndex, int toIndex, byte value) {