RFR: 8263038: Optimize String.format for simple specifiers
Roger Riggs
rriggs at openjdk.java.net
Fri Mar 5 17:11:18 UTC 2021
On Fri, 5 Mar 2021 17:03:34 GMT, Claes Redestad <redestad at openjdk.org> wrote:
>> src/java.base/share/classes/java/util/Formatter.java line 3017:
>>
>>> 3015: s = ((Character)arg).toString();
>>> 3016: } else if (arg instanceof Byte) {
>>> 3017: byte i = (Byte) arg;
>>
>> Can the pattern matching for instanceof be used here to remove explicit casts. (Supported in JDK 16)
>> s = null;
>> if (arg instanceof Character c) {
>> s = c.toString();
>> } else if (arg instanceof Byte i) {
>> if (Character.isValidCodePoint(i))
>> s = new String(Character.toChars(i));
>> else
>> throw new IllegalFormatCodePointException(i);
>> } else if (arg instanceof Short i) {
>> if (Character.isValidCodePoint(i))
>> s = new String(Character.toChars(i));
>> else
>> throw new IllegalFormatCodePointException(i);
>> } ```
>> etc..
>
> I did think about it, but it seemed to stray a bit too far from the intent of this enhancement.
I only looked at it because of the updates to use switch expressions...
ok, either way.
-------------
PR: https://git.openjdk.java.net/jdk/pull/2830
More information about the core-libs-dev
mailing list