Skip to content

Commit

Permalink
[misc] minor performance improvement reading BIGINT with getInt() / g…
Browse files Browse the repository at this point in the history
…etLong()
  • Loading branch information
rusher committed Oct 12, 2016
1 parent df2bbb7 commit a69ab38
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3183,6 +3183,7 @@ private int parseInt(byte[] rawBytes, ColumnInformation columnInfo) throws SQLEx
case YEAR:
case INTEGER:
case MEDIUMINT:
case BIGINT:
long result = 0;
int length = rawBytes.length;
boolean negate = false;
Expand All @@ -3194,6 +3195,12 @@ private int parseInt(byte[] rawBytes, ColumnInformation columnInfo) throws SQLEx
for (; begin < length; begin++) {
result = result * 10 + rawBytes[begin] - 48;
}
//specific for BIGINT : if value > Long.MAX_VALUE will become negative.
if (result < 0) {
throw new SQLException("Out of range value for column '" + columnInfo.getName() + "' : value "
+ new String(rawBytes, StandardCharsets.UTF_8)
+ " is not in Integer range", "22003", 1264);
}
result = (negate ? -1 * result : result);
rangeCheck(Integer.class, Integer.MIN_VALUE, Integer.MAX_VALUE, result, columnInfo);
return (int) result;
Expand Down Expand Up @@ -3242,6 +3249,7 @@ private long parseLong(byte[] rawBytes, ColumnInformation columnInfo) throws SQL
case YEAR:
case INTEGER:
case MEDIUMINT:
case BIGINT:
long result = 0;
int length = rawBytes.length;
boolean negate = false;
Expand All @@ -3253,6 +3261,12 @@ private long parseLong(byte[] rawBytes, ColumnInformation columnInfo) throws SQL
for (; begin < length; begin++) {
result = result * 10 + rawBytes[begin] - 48;
}
//specific for BIGINT : if value > Long.MAX_VALUE , will become negative until -1
if (result < 0) {
throw new SQLException("Out of range value for column '" + columnInfo.getName() + "' : value "
+ new String(rawBytes, StandardCharsets.UTF_8)
+ " is not in Long range", "22003", 1264);
}
return (negate ? -1 * result : result);
default:
return Long.parseLong(new String(rawBytes, StandardCharsets.UTF_8));
Expand Down

0 comments on commit a69ab38

Please sign in to comment.