Re: RFR: 8258804: Collection.toArray() should use empty array
On Tue, 22 Dec 2020 12:39:23 GMT, David M. Lloyd wrote: >> Comparing to Collection.toArray(new T[size)), the Collection.toArray(new >> T[0]) seems faster, safer and contractually cleaner. In the update, the use >> of Collection.toArray(new T[size)) in the SunJSSE provider implementation is >> replaced with Collection.toArray(new T[0]). >> >> Bug: https://bugs.openjdk.java.net/browse/JDK-8258804 > > src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java line 854: > >> 852: // Use the customized TLS protocols. >> 853: candidates = >> 854: refactored.toArray(new ProtocolVersion[0]); > > If this level of performance improvement is justified, then would it not be > better to use a constant empty array instead of constructing a new one each > time? I think empty array construction could be optimized in the compiler layer. - PR: https://git.openjdk.java.net/jdk/pull/1861
Re: RFR: 8258804: Collection.toArray() should use empty array
On Mon, 21 Dec 2020 23:58:03 GMT, Xue-Lei Andrew Fan wrote: > Comparing to Collection.toArray(new T[size)), he Collection.toArray(new T[0]) > seems faster, safer and contractually cleaner. In the update, the use of > Collection.toArray(new T[size)) in the SunJSSE provider implementation is > replaced with Collection.toArray(new T[0]). > > Bug: https://bugs.openjdk.java.net/browse/JDK-8258804 src/java.base/share/classes/sun/security/ssl/SSLContextImpl.java line 854: > 852: // Use the customized TLS protocols. > 853: candidates = > 854: refactored.toArray(new ProtocolVersion[0]); If this level of performance improvement is justified, then would it not be better to use a constant empty array instead of constructing a new one each time? - PR: https://git.openjdk.java.net/jdk/pull/1861
Re: RFR: 8258804: Collection.toArray() should use empty array
On Mon, 21 Dec 2020 23:58:03 GMT, Xue-Lei Andrew Fan wrote: > Comparing to Collection.toArray(new T[size)), he Collection.toArray(new T[0]) > seems faster, safer and contractually cleaner. In the update, the use of > Collection.toArray(new T[size)) in the SunJSSE provider implementation is > replaced with Collection.toArray(new T[0]). > > Bug: https://bugs.openjdk.java.net/browse/JDK-8258804 Looks fine to me. - Marked as reviewed by mullan (Reviewer). PR: https://git.openjdk.java.net/jdk/pull/1861