RFR: 8334328: Reduce object allocation for FloatToDecimal and DoubleToDecimal [v18]

Claes Redestad redestad at openjdk.org
Wed Jun 26 14:03:12 UTC 2024


On Wed, 26 Jun 2024 13:23:14 GMT, Shaojin Wen <duke at openjdk.org> wrote:

>> src/java.base/share/classes/jdk/internal/math/ToDecimal.java line 47:
>> 
>>> 45:     static final int NAN         = 5 << 8;
>>> 46: 
>>> 47:     static final byte LATIN1 = 0;
>> 
>> I think this somewhat unnecessarily copies names and internal implementation details from `String` (where the `coder` value is used both as a pseudo-boolean and as a shift operand, which is not applicable here). In this context we could use something like `private final boolean latin1;` (all uses of `coder` are just `if (coder == LATIN1)` so it would be simplified to `if (latin1)`)
>
> I have written a version using boolean locally, but because this class is mainly used by String and StringBuilder, it uses the same style as String/StringBuilder.

Yeah, I'm just musing about the perils of leaking/replicating those implementation details, but as you say this is internal code only used by `String` and `StringBuilder` to it's loosely part of that complex. Not requesting any changes here for now..

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/19730#discussion_r1654924418


More information about the core-libs-dev mailing list