RFR: 8270160: Remove redundant bounds check from AbstractStringBuilder.charAt() [v3]

Сергей Цыпанов github.com+10835776+stsypanov at openjdk.java.net
Thu Jul 15 11:56:31 UTC 2021


> `AbstractStringBuilder.charAt(int)` does bounds check before calling `charAt()` (for non-latin Strings):
> 
> @Override
> public char charAt(int index) {
>     checkIndex(index, count);
>     if (isLatin1()) {
>         return (char)(value[index] & 0xff);
>     }
>     return StringUTF16.charAt(value, index);
> }
> 
> This can be improved by removing bounds check from ASB.charAt() in favour of one in String*.charAt(). This gives slight improvement:
> 
> before
> Benchmark                           Mode  Cnt  Score   Error  Units
> StringBuilderCharAtBenchmark.latin  avgt   50  2,827 ± 0,024  ns/op
> StringBuilderCharAtBenchmark.utf    avgt   50  2,985 ± 0,020  ns/op
> 
> after
> Benchmark                           Mode  Cnt  Score   Error  Units
> StringBuilderCharAtBenchmark.latin  avgt   50  2,434 ± 0,004  ns/op
> StringBuilderCharAtBenchmark.utf    avgt   50  2,631 ± 0,004  ns/op

Сергей Цыпанов has refreshed the contents of this pull request, and previous commits have been removed. The incremental views will show differences compared to the previous content of the PR. The pull request contains two new commits since the last revision:

 - Merge branch 'master' into 8270160
   
   # Conflicts:
   #	src/java.base/share/classes/java/lang/StringLatin1.java
 - 8270160: Remove redundant bounds check from AbstractStringBuilder.charAt()

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

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/4738/files
  - new: https://git.openjdk.java.net/jdk/pull/4738/files/9f30e621..b7b01ff4

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=4738&range=02
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=4738&range=01-02

  Stats: 1 line in 1 file changed: 0 ins; 1 del; 0 mod
  Patch: https://git.openjdk.java.net/jdk/pull/4738.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/4738/head:pull/4738

PR: https://git.openjdk.java.net/jdk/pull/4738


More information about the core-libs-dev mailing list