On Mon, 19 Sep 2022 16:36:00 GMT, Alexey Ivanov <aiva...@openjdk.org> wrote:
>> ScientificWare has updated the pull request incrementally with one >> additional commit since the last revision: >> >> Corrects typos and digit extraction. >> >> Corrects typos. >> And applies a better digit extraction as suggested in main-line review >> thread. > > src/java.desktop/share/classes/javax/swing/text/html/CSS.java line 1366: > >> 1364: digits = digits.substring(1, Math.min(n, 9)); >> 1365: n--; >> 1366: } > > Should the method return `null` immediately if `n < 3 || n > 8` after the if > block at lines 1363-1366? It's already known the format is invalid. > > I also propose adding `hex.matcher(digits).matches()` here to avoid running > the matcher at each attempt. > > In short, the next statement should be: > > > if (n < 3 || n == 7 || n > 8 || !hex.matcher(digits).matches()) { > return null; > } > > > The following code deals with a valid color notation. @aivanov-jdk, I suppose that most of color notations are correct. Adding these tests in first place has a time cost. With `&&`, `hex.matcher(digits).matches()` is evaluated only once. That why I separated length test from hex test. Pattern usage has a significant time cost. ------------- PR: https://git.openjdk.org/jdk/pull/10317