On Thu, 18 Jul 2024 11:32:47 GMT, Shaojin Wen <[email protected]> wrote:
> 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.
This pull request has now been integrated.
Changeset: 0898ab7f
Author: Shaojin Wen <[email protected]>
Committer: Chen Liang <[email protected]>
URL:
https://git.openjdk.org/jdk/commit/0898ab7f7496689e5de52a5dc4530ca21def1fca
Stats: 164 lines in 3 files changed: 158 ins; 0 del; 6 mod
8336741: Optimize LocalTime.toString with StringBuilder.repeat
Reviewed-by: liach, rriggs, naoto
-------------
PR: https://git.openjdk.org/jdk/pull/20232