RFR: 8334328: Reduce object allocation for FloatToDecimal and DoubleToDecimal [v20]
Shaojin Wen
duke at openjdk.org
Wed Jun 26 22:05:11 UTC 2024
On Wed, 26 Jun 2024 17:42:13 GMT, Chen Liang <liach at openjdk.org> wrote:
>> Shaojin Wen has updated the pull request incrementally with one additional commit since the last revision:
>>
>> 1. revert code change.
>> 2. comment remove space
>
> src/java.base/share/classes/jdk/internal/math/DoubleToDecimal.java line 194:
>
>> 192: * otherwise NON_SPECIAL
>> 193: */
>> 194: private int toDecimal(byte[] str, int index, double v, FormattedFPDecimal fd) {
>
> This `toDecimal` returns packed int with info but the other returns the new index; this is extremely confusing for future readers, especially that they have very similar signatures (difference in signature is in the middle). I recommend making this return a `long` so when it's downcasted to an int, it's just the size (like String concat's coderIndex)
The maximum length of float to decimal is 15, and the maximum length of double to decimal is 24, so one byte is enough. If we use the long return type, we have to add `cast int to long` and `cast long to int` to the code, which is redundant. It will also confuse people, thinking that float to decimal and double to decimal will have a large length, just like the size of string concat, which requires a complete int.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/19730#discussion_r1655573216
More information about the core-libs-dev
mailing list