On Sat, 17 Sep 2022 17:00:30 GMT, ExE Boss <d...@openjdk.org> wrote: >> ScientificWare has updated the pull request incrementally with one >> additional commit since the last revision: >> >> Removes author name. >> >> Removes author name for JDK main-line development repository. > > src/java.desktop/share/classes/javax/swing/text/html/CSS.java line 1404: > >> 1402: } else if (n != 8 || !hex.matcher(digits).matches()) { >> 1403: return null; >> 1404: } > > Using `charAt` avoids creating temporary strings of length `1`. > > Also, using the `%[argument_index$]conversion` format specifier form allows > halving the lengths of the vararg arrays. > Suggestion: > > if (n == 3 && hex.matcher(digits).matches()) { > final char r = digits.charAt(0); > final char g = digits.charAt(1); > final char b = digits.charAt(2); > digits = String.format("%1$s%1$s%2$s%2$s%3$s%3$sff", r, g, b); > } else if (n == 4 && hex.matcher(digits).matches()) { > final char r = digits.charAt(0); > final char g = digits.charAt(1); > final char b = digits.charAt(2); > final char a = digits.charAt(3); > digits = String.format("%1$s%1$s%2$s%2$s%3$s%3$s%4$s%4$s", r, g, > b, a); > } else if (n == 6 && hex.matcher(digits).matches()) { > digits += "ff"; > } else if (n != 8 || !hex.matcher(digits).matches()) { > return null; > }
@ExE-Boss After a quick performance test, I note that `%1$s%1$s%2$s%2$s%3$s%3$s%4$s%4$s` usage multiplies time execution at least by 4. I'm going to test if there is other solutions than %n$s or %s. First of all by using a simple concatenation. ------------- PR: https://git.openjdk.org/jdk/pull/10317