On Sat, 4 Jan 2025 18:18:47 GMT, j3graham <d...@openjdk.org> wrote: > Some other thoughts that might help here; except for leading zeros, 9 (or 18 > for a long) or fewer digits cannot overflow. So something like this might > work: > > * read first char and check if it is a sign character. > * skip leading zeros > * loop over up to 9 digits, performing the calculation without needing to > check for overflow. I think it would be enough to do this 1 digit at a time. > * If there are any digits left, take only the next digit, and incorporate it > into the result while doing the overflow check. > * If there are still more digits left it is too big to fit. > > This approach could also be taken for the more general parse methods.
Thanks for your advice! 1. The current implementation is to determine whether the first character is `+/-`, but the writing method is to reduce the CodeSize, which is not easy to read, but I added a comment. int neg; if ((neg = (c = value[0]) - '-') != 0 && neg + 2 != 0 // firstChar != '+' ) { 2. The leading zero scenario is not common, and there is no need to optimize this scenario. 3. The current cost of judging result < MULT_MIN_10 or result < MULT_MIN_100 is not high. 4. It is necessary to control codeSize <= 325 to enable inline. The code here is written with the minimum codeSize ------------- PR Comment: https://git.openjdk.org/jdk/pull/22919#issuecomment-2571447521