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:
ray.j.greenwell
2010-08-25 19:05:17 +00:00
parent b78365ea6d
commit 3dcef4a00c
@@ -70,16 +70,15 @@ public abstract class BaseArrayList<E> extends AbstractList<E>
if (target.length < _size) {
target = (T[])Array.newInstance(
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
if (_elements != null) {
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;
}