maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <>
Subject [GitHub] [maven] Tibor17 edited a comment on issue #261: [MNG-6697] New fast model interpolator not using reflection
Date Tue, 30 Jul 2019 16:52:10 GMT
Tibor17 edited a comment on issue #261: [MNG-6697] New fast model interpolator not using reflection
   > @Tibor17
   > this is surprisingly not true, indeed Collection.toArray( new Xxxx[0] ) is faster
than Collection.toArray( new Xxxx[collection.size()] ).
   In Oracle JDK, `ArrayList.toArray([])` with `new Xxxx[arrayList.size()]` should be the
same speed as with `new Xxxx[0]`.
   In another vendor of JDK you do not have the benefits of JavaDoc because the resulting
array would not be yours (nothing but imitation of array) and `new Xxxx[0]` may become slower.
   Oracle allocates new array without reflection because given size is smaller than the size
of the collection and the type is `Object[]`.
   This is related to the Oracle and IMO another vendor may get worse performance if he is
using Reflection `Array.newInstance()`.
   The reflection is also used in Oracle if and only if the internal array of the collection
is not `Object[]`.
   I guess that `new MyClass[0]` may get even slower because Generic type is usually not identical
to `Object.class` in the most Java code and JVM has to perform checks of the type on every
element, see `(T[]) new Object[newLength]` which happens in case of `new Xxxx[0]`.
   public static <T,U> T[] copyOf(U[] original, int newLength, Class<? extends T[]>
newType) {
   	T[] copy = ((Object)newType == (Object)Object[].class)
   		? (T[]) new Object[newLength]
   		: (T[]) Array.newInstance(newType.getComponentType(), newLength);
   	System.arraycopy(original, 0, copy, 0,
   					 Math.min(original.length, newLength));
   	return copy;
   public <T> T[] toArray(T[] a) {
   	if (a.length < size)
   		// Make a new array of a's runtime type, but my contents:
   		return (T[]) Arrays.copyOf(elementData, size, a.getClass());
   	System.arraycopy(elementData, 0, a, 0, size);
   	if (a.length > size)
   		a[size] = null;
   	return a;

This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:

With regards,
Apache Git Services

View raw message