harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Hindess <mark.hind...@googlemail.com>
Subject Re: [classlib][luni] Collections classes - code reviews and optimisations
Date Thu, 05 Aug 2010 14:13:38 GMT

In message <201008041456.o74EuNhO004999@d12av03.megacenter.de.ibm.com>,
Mark Hindess writes:
> I've now refactored the exception code to the start of the methods and
> shuffled some of the if else cases around a little.
> Next I plan to look at:
> 1) remove the following from addAll(...):
>          if (this == collection) {
>              collection = (ArrayList)clone();
>          }
>    since it is immediately followed by a call to collection.toArray() so
>    it should be unnecessary.

Done in r982377.  I also checked in the review comments we made to make it
easier to track them.

> 2) Change the fields to firstIndex and size.

I've now done this and checked it in at r982498.

I also made a minor change (below) to ensureCapacity that Oliver
observed does (accidentally) fix a bug that caused us to call a grow
method with 0 growSize and do a pointless array copy shuffling the
entire list.

     public void ensureCapacity(int minimumCapacity) {
-        if (array.length < minimumCapacity) {
+        int required = minimumCapacity - array.length;
+        if (required > 0) {
             // REVIEW: Why do we check the firstIndex first? Growing
             //         the end makes more sense
             if (firstIndex > 0) {
-                growAtFront(minimumCapacity - array.length);
+                growAtFront(required);
             } else {
-                growAtEnd(minimumCapacity - array.length);
+                growAtEnd(required);

My initial (dacapo) benchmark runs on the original ArrayList, the
version with exception refactoring, the version without the spurious
clone and the version with the size changes seem to show that the
exception handling change was a bad idea but that we get back the lost
performance with the size change.  I'm just re-running the benchmarks
on a quiet(er) machine to confirm.  Will post details when they've


View raw message