RFR: 8291641: Optimize StackTraceElement.toString()

Сергей Цыпанов duke at openjdk.org
Mon Aug 1 17:31:52 UTC 2022


On Thu, 28 Jul 2022 13:07:01 GMT, David Schlosnagle <duke at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/StackTraceElement.java line 400:
>> 
>>> 398:                 dest.append(fileName)
>>> 399:                         .append(':')
>>> 400:                         .append(Integer.toString(lineNumber))
>> 
>> I think `Integer.toString(lineNumber)` is redundant here, you can pass `int` directly
>
> `Appendable` does not currently have an `append(int)` method on the interface, though `StringBuilder` does. We could add it to `Appendable` via default method if so desired:
> 
> 
> default Appendable append(int value) {
>     return append(Integer.toString(value));
> }

I think in this case it's better to specify `StringBuilder` instead of `Appendable`, because the method is private and you'd hardly ever pass there anything different from SB.

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

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


More information about the core-libs-dev mailing list