Skip to content

Commit

Permalink
Improve performance of readLong function unrolling loop and using bit…
Browse files Browse the repository at this point in the history
…wise

operators instead of additions
  • Loading branch information
Roberto Navarro committed Jul 30, 2018
1 parent 3bef06c commit aeb106e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/java/com/microsoft/sqlserver/jdbc/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down

0 comments on commit aeb106e

Please sign in to comment.