Skip to content

Commit

Permalink
Fix #967 (#973): BigDecimalParser performance for edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 4, 2023
1 parent eb85a33 commit d260858
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ No changes since 2.14
#912: Optional padding Base64Variant still throws exception on missing
padding character
(reported by @Vity01)
#967: Address performance issue with `BigDecimalParser`

2.14.2 (28-Jan-2023)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ private static BigDecimal toBigDecimalRec(final char[] chars, final int off, fin
return left.add(right);
}

return len == 0 ? BigDecimal.ZERO : new BigDecimal(chars, off, len).movePointRight(scale);
if (len == 0) {
return BigDecimal.ZERO;
}
// 02-Apr-2023, tatu: [core#967] Looks like "scaleByPowerOfThen" avoids performance issue
// there would be with "movePointRight" (both doing about same thing), so)
return new BigDecimal(chars, off, len)
// .movePointRight(scale);
.scaleByPowerOfTen(scale);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class PerfBigDecimalParser967
private final JsonFactory JSON_F = new JsonFactory();

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

0 comments on commit d260858

Please sign in to comment.