RFR: 8336741: Optimize LocalTime.toString with StringBuilder.repeat [v4]

Shaojin Wen duke at openjdk.org
Thu Jul 18 15:43:05 UTC 2024


> class LocalTime {
>     public String toString() {
>         // ...
>                 if (nanoValue % 1000_000 == 0) {
>                     buf.append(Integer.toString((nanoValue / 1000_000) + 1000).substring(1));
>                 } else if (nanoValue % 1000 == 0) {
>                     buf.append(Integer.toString((nanoValue / 1000) + 1000_000).substring(1));
>                 } else {
>                     buf.append(Integer.toString((nanoValue) + 1000_000_000).substring(1));
>                 }
>        // ...
>     }
> }
> 
> Currently, LocalTime.toString handles nanos by adding a value and then subString(1) to fill it with zeros. Using StringBuilder.repeat is more concise and has better performance.

Shaojin Wen has updated the pull request incrementally with one additional commit since the last revision:

  copyright

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/20232/files
  - new: https://git.openjdk.org/jdk/pull/20232/files/be7daa68..d930eb37

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=20232&range=03
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=20232&range=02-03

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

PR: https://git.openjdk.org/jdk/pull/20232


More information about the core-libs-dev mailing list