The reason the patched code is faster is because it will avoid an array resize 
that is triggered in the benchmark by:
 "// once a new ArrayList is created add a new element
        al.add(new Integer(900));"
http://cr.openjdk.java.net/~sgroeger/perf/arraylist/ArrayListBenchmark.java


If you look at the patch, it is over provisioning the backing array by using 
"elements.length" (elementData = new Object[((ArrayList)c).elementData.length];)
instead of "size".  The toArray call uses size and then the benchmark adds one 
element to trigger the resize.

Not sure if over provisioning the backing array is the right choice.  I tend to 
lean towards the current paradigm of exact sizing on copy.

Jason


Reply via email to