From aeb106ee12b94bcf630e87caa36143b3db72ec4f Mon Sep 17 00:00:00 2001 From: Roberto Navarro Date: Mon, 30 Jul 2018 10:13:54 +0200 Subject: [PATCH] Improve performance of readLong function unrolling loop and using bitwise operators instead of additions --- .../java/com/microsoft/sqlserver/jdbc/Util.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/Util.java b/src/main/java/com/microsoft/sqlserver/jdbc/Util.java index d1536e735..2f6e420fb 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/Util.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/Util.java @@ -197,12 +197,14 @@ static BigDecimal readBigDecimal(byte valueBytes[], int valueLength, int scale) * @return long value as read from bytes. */ /* L0 */static long readLong(byte data[], int nOffset) { - long v = 0; - for (int i = 7; i > 0; i--) { - v += (long) (data[nOffset + i] & 0xff); - v <<= 8; - } - return v + (long) (data[nOffset] & 0xff); + return ((long) (data[nOffset + 7] & 0xff) << 56) + | ((long) (data[nOffset + 6] & 0xff) << 48) + | ((long) (data[nOffset + 5] & 0xff) << 40) + | ((long) (data[nOffset + 4] & 0xff) << 32) + | ((long) (data[nOffset + 3] & 0xff) << 24) + | ((long) (data[nOffset + 2] & 0xff) << 16) + | ((long) (data[nOffset + 1] & 0xff) << 8) + | ((long) (data[nOffset] & 0xff)); } /**