RFR: 8377427: Reduce substring allocations in Color.web(String, double) [v2]
Andy Goryachev
angorya at openjdk.org
Tue Feb 10 15:39:26 UTC 2026
On Tue, 10 Feb 2026 00:29:04 GMT, Michael Strauß <mstrauss at openjdk.org> wrote:
>> modules/javafx.graphics/src/main/java/javafx/scene/paint/Color.java line 517:
>>
>>> 515: int limit = end;
>>> 516:
>>> 517: while (start < limit && Character.isWhitespace(color.charAt(start))) {
>>
>> I think this change is not equivalent: the `trim()` function (used before) removes leading and trailing "spaces" which are defined as `space is defined as any character whose codepoint is less than or equal to 'U+0020' (the space character).`
>>
>> `Character.isWhitespace()` is different:
>>
>>
>> hex| trim| isWhitespace
>> 0x00 W -
>> 0x01 W -
>> 0x02 W -
>> 0x03 W -
>> 0x04 W -
>> 0x05 W -
>> 0x06 W -
>> 0x07 W -
>> 0x08 W -
>> 0x09 W W
>> 0x0a W W
>> 0x0b W W
>> 0x0c W W
>> 0x0d W W
>> 0x0e W -
>> 0x0f W -
>> 0x10 W -
>> 0x11 W -
>> 0x12 W -
>> 0x13 W -
>> 0x14 W -
>> 0x15 W -
>> 0x16 W -
>> 0x17 W -
>> 0x18 W -
>> 0x19 W -
>> 0x1a W -
>> 0x1b W -
>> 0x1c W W
>> 0x1d W W
>> 0x1e W W
>> 0x1f W W
>> 0x20 W W
>>
>>
>> see https://github.com/andy-goryachev-oracle/Test/blob/main/test/goryachev/research/TestWhitespace.java
>
> While that's true, I think it is irrelevant. `Color.web()` is not specified to just skip over non-whitespace control characters inside of a color function, and it is not prudent to assume that a string parsing function would silently skip over non-whitespace control characters by default.
I am pointing out a non-zero chance of regression, for instance when this method is used to parse an external poorly formatted file with no sanitizing.
I do agree that this change is probably fine though.
-------------
PR Review Comment: https://git.openjdk.org/jfx/pull/2069#discussion_r2788695855
More information about the openjfx-dev
mailing list