提交 e063498f authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Do not allocate String for BigDecimal() in readDecimal()

上级 5288eafc
...@@ -4687,17 +4687,19 @@ public class Parser { ...@@ -4687,17 +4687,19 @@ public class Parser {
private void readDecimal(int start, int i) { private void readDecimal(int start, int i) {
char[] chars = sqlCommandChars; char[] chars = sqlCommandChars;
int[] types = characterTypes; int[] types = characterTypes;
boolean integer = true;
// go until the first non-number // go until the first non-number
while (true) { while (true) {
int t = types[i]; int t = types[i];
if (t != CHAR_DOT && t != CHAR_VALUE) { if (t == CHAR_DOT) {
integer = false;
} else if (t != CHAR_VALUE) {
break; break;
} }
i++; i++;
} }
boolean containsE = false;
if (chars[i] == 'E' || chars[i] == 'e') { if (chars[i] == 'E' || chars[i] == 'e') {
containsE = true; integer = false;
i++; i++;
if (chars[i] == '+' || chars[i] == '-') { if (chars[i] == '+' || chars[i] == '-') {
i++; i++;
...@@ -4710,11 +4712,10 @@ public class Parser { ...@@ -4710,11 +4712,10 @@ public class Parser {
} }
} }
parseIndex = i; parseIndex = i;
String sub = sqlCommand.substring(start, i);
checkLiterals(false); checkLiterals(false);
BigDecimal bd; BigDecimal bd;
if (!containsE && sub.indexOf('.') < 0) { if (integer && i - start <= 19) {
BigInteger bi = new BigInteger(sub); BigInteger bi = new BigInteger(sqlCommand.substring(start, i));
if (bi.compareTo(ValueLong.MAX_BI) <= 0) { if (bi.compareTo(ValueLong.MAX_BI) <= 0) {
// parse constants like "10000000L" // parse constants like "10000000L"
if (chars[i] == 'L') { if (chars[i] == 'L') {
...@@ -4727,9 +4728,9 @@ public class Parser { ...@@ -4727,9 +4728,9 @@ public class Parser {
bd = new BigDecimal(bi); bd = new BigDecimal(bi);
} else { } else {
try { try {
bd = new BigDecimal(sub); bd = new BigDecimal(sqlCommandChars, start, i - start);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, e, sub); throw DbException.get(ErrorCode.DATA_CONVERSION_ERROR_1, e, sqlCommand.substring(start, i));
} }
} }
currentValue = ValueDecimal.get(bd); currentValue = ValueDecimal.get(bd);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论