On Mon, 23 May 2022 20:15:12 GMT, Sergey Bylokhov <[email protected]> wrote:
>> src/java.desktop/share/classes/java/awt/SystemTray.java line 349:
>>
>>> 347: if (icons != null) {
>>> 348: return icons.toArray(new TrayIcon[0]);
>>> 349: }
>>
>> Actually, the old code is more efficient than your new code.
>> Per the spec
>> https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Vector.html#toArray(T%5B%5D)
>> Returns an array containing all of the elements in this Vector in the
>> correct order; the runtime type of the returned array is that of the
>> specified array. If the Vector fits in the specified array, it is returned
>> therein. Otherwise, a new array is allocated with the runtime type of the
>> specified array and the size of this Vector.
>>
>> So your new code allocates one more array than the old code.
>
> It is not intuitive but the "zero version" is actually faster:
ok ... why ?
-------------
PR: https://git.openjdk.java.net/jdk/pull/8850