RFR: 8315999: Improve Date toString performance [v2]
Claes Redestad
redestad at openjdk.org
Mon Sep 11 14:47:41 UTC 2023
On Mon, 11 Sep 2023 14:38:28 GMT, 温绍锦 <duke at openjdk.org> wrote:
>> src/java.base/share/classes/java/time/LocalDate.java line 2181:
>>
>>> 2179: if (yearAbs < 1000) {
>>> 2180: if (year < 0) {
>>> 2181: buf[off] = '-';
>>
>> `buf[off++] = '-';`
>
> this place doesn't need off++
It was a suggestion, implicitly paired with removing ` + (year < 0 ? 1 : 0)` from line 2188.
>> src/java.base/share/classes/java/time/LocalDate.java line 2192:
>>
>>> 2190: } else {
>>> 2191: if (year > 9999) {
>>> 2192: buf[off] = '+';
>>
>> `buf[off++] = '+';`?
>
> this place doesn't need off++
Correct, though it's a bit opaque that `yearSize` includes room for the `'+'` that gets added on years > 9999 but that `jla.getChars` won't print that. This makes the logic somewhat fragile, which I think could be improved.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15658#discussion_r1321663810
PR Review Comment: https://git.openjdk.org/jdk/pull/15658#discussion_r1321666764
More information about the core-libs-dev
mailing list