mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
override toArray() to use more efficient arraycopy instead of the default iterator() creation/traversing
This commit is contained in:
@@ -582,6 +582,20 @@ public class ContainerUtil extends ContainerUtilRt {
|
||||
public int size() {
|
||||
return myStore.length;
|
||||
}
|
||||
|
||||
// override for more efficient arraycopy vs. iterator() creation/traversing
|
||||
@NotNull
|
||||
@Override
|
||||
public <T> T[] toArray(@NotNull T[] a) {
|
||||
int size = size();
|
||||
//noinspection unchecked
|
||||
T[] result = a.length >= size ? a : (T[])Array.newInstance(a.getClass().getComponentType(), size);
|
||||
System.arraycopy(myStore, 0, result, 0, size);
|
||||
if (result.length > size) {
|
||||
result[size] = null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user