On Mon, 9 Feb 2026 17:27:23 GMT, Roger Riggs <[email protected]> wrote:
>> Tatsunori Uchino has updated the pull request incrementally with two
>> additional commits since the last revision:
>>
>> - Add comment
>> - Fix logic error
>
> src/java.base/share/classes/java/lang/CharSequence.java line 271:
>
>> 269: // All we have to do here is to count the number of surrogate
>> pairs.
>> 270: // The first code unit of a surrogate pair is in [0, lastIndex).
>> 271: for (int i = 0; i < lastIndex;) {
>
> The loop would be more readable and demonstrabily correct if the i++ was in
> the usual place in `for` and not auto incremented in the middle of a
> conditional.
I don't think so. Your suggestion doesn't simplify the code:
boolean precededByHigh = false;
for (int i = 0; i < lastIndex; i++) {
char c = charAt(i);
if (precededByHigh) {
if (Character.isLowSurrogate(c)) {
n--;
}
precededByHigh = false;
} else {
precededByHigh = Character.isHighSurrogate(c);
}
}
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26461#discussion_r2901120115