On Wed, 15 May 2024 07:16:37 GMT, Claes Redestad <redes...@openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/constant/ClassDesc.java line 226:
>> 
>>> 224:         for (int i = 0; i < rank; i++) {
>>> 225:             sb.append('[');
>>> 226:         }
>> 
>> Would `sb.repeat("[", rank);` be better here?
>> 
>> Also for parity with `arrayType()` I recommend moving this building code to 
>> after the void check.
>
> Oh, that's new (in 21). I was comparing against `append("[".repeat(rank))` 
> which had a cost here. `sb.repeat('[', rank)` is in the same ballpark and 
> simpler. Fixing.
> 
> 
> Benchmark                                       Mode  Cnt     Score     Error 
>   Units
> ClassDescMethods.arrayType2                     avgt   15    31,568 ±   2,108 
>   ns/op
> ClassDescMethods.arrayType2:gc.alloc.rate.norm  avgt   15   256,000 ±   0,001 
>    B/op
> 
> 
> I'll align the code to construct `newDesc` before the void check in both 
> methods.

Didn't realize the char version actually takes an int codepoint 😄 so I 
suggested the String one.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/19105#discussion_r1601477998

Reply via email to