From 3dcef4a00cdba6c49e2250a00b2369a2663d1a50 Mon Sep 17 00:00:00 2001 From: "ray.j.greenwell" Date: Wed, 25 Aug 2010 19:05:17 +0000 Subject: [PATCH] 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 --- src/java/com/samskivert/util/BaseArrayList.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/java/com/samskivert/util/BaseArrayList.java b/src/java/com/samskivert/util/BaseArrayList.java index 47bee33d..e8a5e54f 100644 --- a/src/java/com/samskivert/util/BaseArrayList.java +++ b/src/java/com/samskivert/util/BaseArrayList.java @@ -70,16 +70,15 @@ public abstract class BaseArrayList extends AbstractList 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; }