diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 763ef8fc4..df4f0a6eb 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -182,6 +182,8 @@ Changed classes / methods Fixed Bugs ---------- + o [COLLECTIONS-472] Improved performance of "AbstractMapBag#containsAll(Collection)" by returning immediately + after a difference has been found. Thanks to Adrian Nistor. o [COLLECTIONS-461] Added additional clarification to javadoc of interface "Put" wrt return type of "put(Object, Object)" method. Thanks to Matt Benson, sebb. o [COLLECTIONS-447] Tree traversal with a TreeListIterator will not be affected anymore by the removal of an element directly after diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 8eb78ab8f..576e01086 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,6 +22,10 @@ + + Improved performance of "AbstractMapBag#containsAll(Collection)" by returning immediately + after a difference has been found. + Replaced "Collection" with "Iterable" for method arguments where applicable. diff --git a/src/main/java/org/apache/commons/collections4/bag/AbstractMapBag.java b/src/main/java/org/apache/commons/collections4/bag/AbstractMapBag.java index 6c85c8af9..4a9c52716 100644 --- a/src/main/java/org/apache/commons/collections4/bag/AbstractMapBag.java +++ b/src/main/java/org/apache/commons/collections4/bag/AbstractMapBag.java @@ -147,14 +147,14 @@ public abstract class AbstractMapBag implements Bag { * @return true if the Bag contains all the collection */ boolean containsAll(final Bag other) { - boolean result = true; final Iterator it = other.uniqueSet().iterator(); while (it.hasNext()) { final Object current = it.next(); - final boolean contains = getCount(current) >= other.getCount(current); - result = result && contains; + if (getCount(current) < other.getCount(current)) { + return false; + } } - return result; + return true; } //-----------------------------------------------------------------------