RFR: 8377427: Reduce substring allocations in Color.web(String, double) [v2]
Michael Strauß
mstrauss at openjdk.org
Tue Feb 10 15:15:19 UTC 2026
On Tue, 10 Feb 2026 15:09:55 GMT, Michael Strauß <mstrauss at openjdk.org> wrote:
>> Color.web(string, double) parses a color string by creating substrings of the input. Almost all of these string allocations can be removed, except for an invocation of `Double.parseDouble(String)`, which doesn't have an overload that accepts a sub-range of the input string.
>>
>> There are no new tests for this enhancement, since the existing tests already cover all relevant code paths.
>
> Michael Strauß has updated the pull request incrementally with one additional commit since the last revision:
>
> CSS-compliant double parser
> Use of `parseDouble` is questionable anyway (unless input was sanitized first) as it is a Java double parser. For example, this works:
>
> ```java
> Color.web("rgba(2, 2, 1, 0.25e2f)")
> ```
You're right, the specification of `Color.web()` explicitly states: _Creates an RGB color specified with an HTML or CSS attribute string_.
Not every string that is parsed by `Double.parseDouble()` is a valid CSS number, and if it is not, it should be rejected by `Color.web()`. I've added code that parses a number according to CSS grammar. With this change, color parsing is now completely allocation-free.
-------------
PR Comment: https://git.openjdk.org/jfx/pull/2069#issuecomment-3878370660
More information about the openjfx-dev
mailing list