<i18n dev> RFR: 8300818: Reduce complexity of padding with DateTimeFormatter [v6]

Claes Redestad redestad at openjdk.org
Fri Apr 21 14:34:46 UTC 2023


On Thu, 20 Apr 2023 15:05:18 GMT, Sergey Tsypanov <stsypanov at openjdk.org> wrote:

>> Currently it's O(n) - we do `n` shifts of bytes within `StringBuilder`. This can be reduced to O(1) improving the code like:
>> 
>> DateTimeFormatter dtf = new DateTimeFormatterBuilder()
>>   .appendLiteral("Date:")
>>   .padNext(20, ' ')
>>   .append(DateTimeFormatter.ISO_DATE)
>>   .toFormatter();
>> String text = dtf.format(LocalDateTime.now());
>
> Sergey Tsypanov has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8300818: Remove blank line

test/micro/org/openjdk/bench/java/time/format/DateTimeFormatterWithPaddingBench.java line 62:

> 60: 
> 61:     @Benchmark
> 62:     public String formatWithZeroPadding() {

Isn't this benchmark now testing a padding of 1 char?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/12131#discussion_r1173847037


More information about the i18n-dev mailing list