On Sun, 1 Feb 2026 12:55:29 GMT, Tatsunori Uchino <[email protected]> wrote:
>> Adds `codePointCount()` overloads to `String`, `Character`,
>> `(Abstract)StringBuilder`, and `StringBuffer` to make it possible to
>> conveniently retrieve the length of a string as code points without extra
>> boundary checks.
>>
>>
>> if (superTremendouslyLongExpressionYieldingAString().codePointCount() >
>> limit) {
>> throw new Exception("exceeding length");
>> }
>>
>>
>> Is a CSR required to this change?
>
> Tatsunori Uchino has updated the pull request incrementally with two
> additional commits since the last revision:
>
> - Add comment
> - Fix logic error
Sorry for the delay.
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.
src/java.base/share/classes/java/nio/X-Buffer.java.template line 2079:
> 2077: // The first code unit of a surrogate pair is in [0, lastIndex).
> 2078: for (; i < lastIndex;) {
> 2079: if (Character.isHighSurrogate(get(i++)) &&
> Character.isLowSurrogate(get(i))) {
Same comment about readability, put the i++ in the usual place in the for.
Leave the optimization to the compiler.
-------------
PR Review: https://git.openjdk.org/jdk/pull/26461#pullrequestreview-3774439460
PR Review Comment: https://git.openjdk.org/jdk/pull/26461#discussion_r2783716242
PR Review Comment: https://git.openjdk.org/jdk/pull/26461#discussion_r2783725326