improved BigDecimal parsing performance#3992
Conversation
- Use bit-shift operations for faster digit parsing - Simplify overflow detection to single check after digit loop - Handle exponent with combined scale to avoid string-based parsing Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
wenshao
left a comment
There was a problem hiding this comment.
The same overflow check is duplicated in core/src/main/java/com/alibaba/fastjson2/JSONReaderUTF16.java and should be fixed there as well.
— gpt-5.5 via Qwen Code /review
| } | ||
| } | ||
|
|
||
| // Check overflow: more than 18 digits, or 19 digits with negative value (sign bit set) |
There was a problem hiding this comment.
[Critical] This post-loop overflow check can accept corrupted 19-digit values. For exactly 19 digits, values greater than Long.MAX_VALUE may overflow during longValue = longValue * 10 + digit and still finish with a non-negative wrapped longValue, so they take the BigDecimal.valueOf(longValue, combinedScale) fast path instead of falling back to TypeUtils.parseBigDecimal(...). That can silently return the wrong BigDecimal for valid JSON numbers outside signed long range.
A safer fix is to restore per-digit overflow detection, or add an exact 19-digit range check before using the accumulated longValue; otherwise force the existing string-based fallback.
— gpt-5.5 via Qwen Code /review
What this PR does / why we need it?
Summary of your change
Please indicate you've done the following: