RFR: JDK-8292276 : Missing color names in CSS. [v2]

ExE Boss duke at openjdk.org
Mon Aug 15 19:43:27 UTC 2022


On Mon, 15 Aug 2022 17:49:32 GMT, ScientificWare <duke at openjdk.org> wrote:

>> This is referenced in Java Bug Database as
>> - [JDK-8292276 : Missing color names in CSS](https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8292276)
>> 
>> This is tracked in JBS as 
>> - [JDK-8292276 : Missing color names in CSS](https://bugs.openjdk.java.net/browse/JDK-8292276)
>> 
>> Adds missing color names, defined by CSS Level 4, in CSS.java :
>> CSS Color Module Level 4
>> W3C Candidate Recommendation Snapshot, 5 July 2022
>> [7.1 Named Colors](https://www.w3.org/TR/css-color-4/#named-color)
>> 
>> Designed from : [ScientificWare JDK-8292276 : Missing color names in CSS](https://github.com/scientificware/jdk/issues/12)
>
> ScientificWare has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Adds to CSS.java the missing color names.
>   
>   Adds to CSS.java, the missing color names defined by :
>   CSS Color Module Level 4
>   W3C Candidate Recommendation Snapshot, 5 July 2022
>   [7.1 Named Colors](https://www.w3.org/TR/css-color-4/#named-color)
>   - Updates, Copyright year.
>   - Adds relative imports.
>   - Replaces, if ... then ... else statements with TreeMap called "colorNamed".
>     Code is more readable and easy to maintain.
>     After tests, HashMap seems slower than TreeMap. Results are available at https://github.com/scientificware/jdk/issues/12#issuecomment-1213978168.
>   
>   Warning : The Previous JDK CSS Orange Color is different from CSS Color Recommendation.

src/java.desktop/share/classes/javax/swing/text/html/CSS.java line 1414:

> 1412:     }
> 1413: 
> 1414:     private static TreeMap<String, Color> colorNamed = new TreeMap<String, Color>(

Why a `TreeMap` instead of just using `Map.ofEntries(…)`?

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

The latter is unmodifiable and its `table` is marked as `@Stable`[^1], which means that the JIT is allowed to treat it as fully constant[^2].

[^1]: https://github.com/openjdk/jdk/blob/ea2c82e74f5580f396920f9e561cbec80c03f373/src/java.base/share/classes/java/util/ImmutableCollections.java#L1164-L1170
[^2]: https://github.com/openjdk/jdk/blob/ea2c82e74f5580f396920f9e561cbec80c03f373/src/java.base/share/classes/jdk/internal/vm/annotation/Stable.java#L64-L72

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

PR: https://git.openjdk.org/jdk/pull/9825



More information about the client-libs-dev mailing list