On Mon, 23 May 2022 17:18:17 GMT, Phil Race <p...@openjdk.org> wrote:
>> **WTrayIconPeer**: removed duplicate call to `popupParent.dispose()` that >> might cause NPE (it looks `popupParent` cannot be `null`); organised imports. >> >> **SystemTray**: removed redundant initialisers; replaced sized array with >> empty array in `toArray` call; dropped `newValue != null` chained with >> `equals`. > > 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: ------------- PR: https://git.openjdk.java.net/jdk/pull/8850