On Wed, 12 May 2021 11:00:25 GMT, Сергей Цыпанов
<[email protected]> wrote:
>> src/java.base/share/classes/java/lang/Class.java line 4351:
>>
>>> 4349:
>>> 4350: if (isArray()) {
>>> 4351: return "[".concat(componentType.descriptorString());
>>
>> This could be optimized further for multi-dimensional arrays:
>>
>> if (isArray()) {
>> int arrayDepth = 1;
>> Class<?> ct = componentType;
>> while (ct.isArray()) {
>> arrayDepth++;
>> ct = ct.componentType;
>> }
>> return "[".repeat(arrayDepth).concat(ct.descriptorString());
>
> But isn't `componentType.descriptorString()` does this itself? Also
> multi-dimensional arrays are quite an infrequent usecase, aren't they?
Yeah, it's just an optimization. Current code wouldbuild "[[..[[LFoo;" by
recursively going down to `Foo`, build and return "LFoo;", then do "[" +
"LFoo;", and so on. Infrequent enough that we can ignore it, sure, but since
it's effectively reducing the algorithmic complexity from O(n*m) to O(n+m) I
should at least mention it.
-------------
PR: https://git.openjdk.java.net/jdk/pull/3627