On Fri, 1 Aug 2025 13:15:29 GMT, Brett Okken <d...@openjdk.org> wrote:

>> As suggested on mailing list, when encoding latin1 bytes to utf-8, we can 
>> count the leading positive bytes and in the case where there is a negative, 
>> we can copy all the positive values to the target byte[] prior to processing 
>> the remaining data 1 byte at a time.
>> 
>> https://mail.openjdk.org/pipermail/core-libs-dev/2025-July/149417.html
>
> Brett Okken has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   coding conventions

src/java.base/share/classes/java/lang/String.java line 1293:

> 1291: 
> 1292:         byte[] dst = StringUTF16.newBytesFor(val.length);
> 1293:         if (positives > 0) {

I wonder if for very short strings, the overhead of the setup for `arraycopy` 
is worth it.
It might be interesting to raise the test here to 4 or 8 for the array copy  
and otherwise start the loop at 0 and see if the performance difference is 
detectable.

src/java.base/share/classes/java/lang/String.java line 1297:

> 1295:         }
> 1296:         int dp = positives;
> 1297:         for (int i=dp; i<val.length; ++i) {

Spaces are preferred around operators.  (Match style in the rest of the file).

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26597#discussion_r2248269084
PR Review Comment: https://git.openjdk.org/jdk/pull/26597#discussion_r2248254384

Reply via email to