commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joachim Rudolph (JIRA)" <j...@apache.org>
Subject [jira] Created: (COLLECTIONS-302) CollectionUtils.subtract() should not use ArrayList to improve speed
Date Wed, 13 Aug 2008 11:00:44 GMT
CollectionUtils.subtract() should not use ArrayList to improve speed
--------------------------------------------------------------------

                 Key: COLLECTIONS-302
                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-302
             Project: Commons Collections
          Issue Type: Improvement
          Components: Collection
            Reporter: Joachim Rudolph
            Priority: Minor


The implementation of version 3.2.1 is
public static Collection subtract(final Collection a, final Collection b) {
        ArrayList list = new ArrayList( a );
        for (Iterator it = b.iterator(); it.hasNext();) {
            list.remove(it.next());
        }
        return list;
    }
when a and b are large and similar the subtract implementation will call ArrayList.remove()
frequently which copies a potentially large part of the list using system.arraycopy.

Suggestion : use LinkedList ( at least for large lists )

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message