RFR: 8263552: Use String.valueOf() for char-to-String conversion in ObjectStreamClass

Сергей Цыпанов github.com+10835776+stsypanov at openjdk.java.net
Sat Mar 13 14:27:19 UTC 2021


On Mon, 22 Feb 2021 12:04:14 GMT, Conor Cleary <ccleary at openjdk.org> wrote:

>> This is a very simple and trivial improvement about getting rid of pointless char wrapping into array
>
> src/java.base/share/classes/java/io/ObjectStreamClass.java line 833:
> 
>> 831:             String fname = in.readUTF();
>> 832:             String signature = ((tcode == 'L') || (tcode == '[')) ?
>> 833:                 in.readTypeString() : String.valueOf(tcode);
> 
> Certainly more readable and it seems that the call to valueOf is equivalent to whay takes place with the original code. I can't see any difference semantically or performance-wise at a glance. LGTM

@c-cleary Thanks for review. The difference is about intermediate array: `String.valueOf()` doesn't allocate it being slightly faster and less memory-consuming.

Could you file an issue to track this? I'm not an Oracle employee and not able to do it myself.

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

PR: https://git.openjdk.java.net/jdk/pull/2660


More information about the core-libs-dev mailing list