Skip to content

Commit d260858

Browse files
committed
Fix #967 (#973): BigDecimalParser performance for edge cases
1 parent eb85a33 commit d260858

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

release-notes/VERSION-2.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ No changes since 2.14
2525
#912: Optional padding Base64Variant still throws exception on missing
2626
padding character
2727
(reported by @Vity01)
28+
#967: Address performance issue with `BigDecimalParser`
2829

2930
2.14.2 (28-Jan-2023)
3031

src/main/java/com/fasterxml/jackson/core/io/BigDecimalParser.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,13 @@ private static BigDecimal toBigDecimalRec(final char[] chars, final int off, fin
178178
return left.add(right);
179179
}
180180

181-
return len == 0 ? BigDecimal.ZERO : new BigDecimal(chars, off, len).movePointRight(scale);
181+
if (len == 0) {
182+
return BigDecimal.ZERO;
183+
}
184+
// 02-Apr-2023, tatu: [core#967] Looks like "scaleByPowerOfThen" avoids performance issue
185+
// there would be with "movePointRight" (both doing about same thing), so)
186+
return new BigDecimal(chars, off, len)
187+
// .movePointRight(scale);
188+
.scaleByPowerOfTen(scale);
182189
}
183190
}

src/test/java/com/fasterxml/jackson/failing/PerfBigDecimalParser967.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class PerfBigDecimalParser967
1111
private final JsonFactory JSON_F = new JsonFactory();
1212

1313
// For [core#967]: shouldn't take multiple seconds
14-
@Test(timeout = 35000)
14+
@Test(timeout = 3000)
1515
public void bigDecimalFromString() throws Exception {
1616
// Jackson's BigDecimalParser seems to be slower than JDK's;
1717
// won't fail if using latter.

0 commit comments

Comments
 (0)