mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8196207: Inefficient ArrayList.subList().toArray()
Reviewed-by: martin, psandoz, jrose, redestad
This commit is contained in:
parent
35a7cc10b7
commit
bbb4bcd69d
3 changed files with 124 additions and 34 deletions
|
@ -1143,6 +1143,23 @@ public class ArrayList<E> extends AbstractList<E>
|
|||
return modified;
|
||||
}
|
||||
|
||||
public Object[] toArray() {
|
||||
checkForComodification();
|
||||
return Arrays.copyOfRange(root.elementData, offset, offset + size);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T[] toArray(T[] a) {
|
||||
checkForComodification();
|
||||
if (a.length < size)
|
||||
return (T[]) Arrays.copyOfRange(
|
||||
root.elementData, offset, offset + size, a.getClass());
|
||||
System.arraycopy(root.elementData, offset, a, 0, size);
|
||||
if (a.length > size)
|
||||
a[size] = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
public Iterator<E> iterator() {
|
||||
return listIterator();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue