RFR: 8325340: Add ASCII fast-path to Data-/ObjectInputStream.readUTF
Chen Liang
liach at openjdk.org
Tue Feb 13 16:13:12 UTC 2024
On Tue, 6 Feb 2024 16:17:21 GMT, Claes Redestad <redestad at openjdk.org> wrote:
> Adding a fast-path for ASCII-only modified UTF-8 strings deserialied via Data- and ObjectInputStream
>
> Testing: tier1-3
src/java.base/share/classes/java/io/ObjectInputStream.java line 3688:
> 3686: // avoid a redundant scan
> 3687: String utf = new String(buf, pos, (int)utflen, StandardCharsets.ISO_8859_1);
> 3688: pos += (int)utflen;
Suggestion:
String utf = new String(buf, pos, ascii, StandardCharsets.ISO_8859_1);
pos += ascii;
Redundant casts
src/java.base/share/classes/java/io/ObjectInputStream.java line 3746:
> 3744: int avail = Math.min(end - pos, CHAR_BUF_SIZE);
> 3745: // stop short of last char unless all of utf bytes in buffer
> 3746: int stop = start + ((utflen > avail) ? avail - 2 : (int) utflen);
Though reading LV instead of getfield is an improvement, we probably prefer to keep this patch cleaner.
src/java.base/share/classes/java/nio/charset/Charset.java line 682:
> 680: else
> 681: defaultCharset = sun.nio.cs.UTF_8.INSTANCE;
> 682: Charset.forName("UTF-8");
Redundant debug code?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/17734#discussion_r1480387150
PR Review Comment: https://git.openjdk.org/jdk/pull/17734#discussion_r1480389129
PR Review Comment: https://git.openjdk.org/jdk/pull/17734#discussion_r1480391246
More information about the nio-dev
mailing list