RFR: 8364320: String encodeUTF8 latin1 with negatives
Chen Liang
liach at openjdk.org
Fri Aug 1 12:58:54 UTC 2025
On Fri, 1 Aug 2025 12:34:15 GMT, Brett Okken <duke at 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
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) {
Suggestion:
for (int i = dp; i < val.length; ++i) {
Though we usually use `i++` more often, `++i` should be fine too.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26597#discussion_r2247915445
More information about the core-libs-dev
mailing list