Micro-optimization: don't test the array length if we just created it
at the right size. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2806 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -70,16 +70,15 @@ public abstract class BaseArrayList<E> extends AbstractList<E>
|
|||||||
if (target.length < _size) {
|
if (target.length < _size) {
|
||||||
target = (T[])Array.newInstance(
|
target = (T[])Array.newInstance(
|
||||||
target.getClass().getComponentType(), _size);
|
target.getClass().getComponentType(), _size);
|
||||||
}
|
|
||||||
|
|
||||||
|
} else if (target.length > _size) {
|
||||||
|
// terminate with null if there is room to spare, per the spec
|
||||||
|
target[_size] = null;
|
||||||
|
}
|
||||||
// copy the elements
|
// copy the elements
|
||||||
if (_elements != null) {
|
if (_elements != null) {
|
||||||
System.arraycopy(_elements, 0, target, 0, _size);
|
System.arraycopy(_elements, 0, target, 0, _size);
|
||||||
}
|
}
|
||||||
// terminate with null if there is room to spare, per the spec
|
|
||||||
if (target.length > _size) {
|
|
||||||
target[_size] = null;
|
|
||||||
}
|
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user