RFR: 8339699: Optimize DataOutputStream writeUTF [v3]

ExE Boss duke at openjdk.org
Sat Sep 7 14:15:04 UTC 2024


On Sat, 7 Sep 2024 08:51:25 GMT, Shaojin Wen <swen at openjdk.org> wrote:

>> PR #20772 introduced an optimization for writeUTF, which can also be used in DataOutputStream::writeUTF.
>
> Shaojin Wen has updated the pull request incrementally with one additional commit since the last revision:
> 
>   reduce JDKUTF#utflen codeSize

src/java.base/share/classes/java/io/DataOutputStream.java line 382:

> 380:         ByteArray.setUnsignedShort(bytearr, count, utflen);
> 381:         count += 2;
> 382:         str.getBytes(0, countNonZeroAscii, bytearr, count);

Maybe the deprecated [`String​::getBytes​(int, int, byte[], int)`] method calls could be moved to a method in `JDKUTF` in order to avoid having to use overly broad `@SuppressWarnings("deprecation")`:

@ForceInline
@SuppressWarnings("deprecation")
public static void getBytes(String str, int srcPos, byte[] dst, int dstPos, int length) {
	str.getBytes(srcPos, srcPos + length, dst, dstPos);
}


[`String​::getBytes​(int, int, byte[], int)`]: https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/lang/String.html#getBytes(int,int,byte[],int)

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20886#discussion_r1748098802


More information about the core-libs-dev mailing list