Author: tn
Date: Sun Jun  9 18:35:24 2013
New Revision: 1491258

URL: http://svn.apache.org/r1491258
Log:
[COLLECTIONS-472] Improved performance of AbstractMapBag#containsAll. Thanks to 
Adrian Nistor.

Modified:
    commons/proper/collections/trunk/RELEASE-NOTES.txt
    commons/proper/collections/trunk/src/changes/changes.xml
    
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/bag/AbstractMapBag.java

Modified: commons/proper/collections/trunk/RELEASE-NOTES.txt
URL: 
http://svn.apache.org/viewvc/commons/proper/collections/trunk/RELEASE-NOTES.txt?rev=1491258&r1=1491257&r2=1491258&view=diff
==============================================================================
--- commons/proper/collections/trunk/RELEASE-NOTES.txt (original)
+++ commons/proper/collections/trunk/RELEASE-NOTES.txt Sun Jun  9 18:35:24 2013
@@ -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

Modified: commons/proper/collections/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/changes/changes.xml?rev=1491258&r1=1491257&r2=1491258&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/changes/changes.xml (original)
+++ commons/proper/collections/trunk/src/changes/changes.xml Sun Jun  9 
18:35:24 2013
@@ -22,6 +22,10 @@
   <body>
 
   <release version="4.0" date="TBA" description="Next release">
+    <action issue="COLLECTIONS-472" dev="tn" type="fix" due-to="Adrian Nistor">
+      Improved performance of "AbstractMapBag#containsAll(Collection)" by 
returning immediately
+      after a difference has been found.
+    </action>  
     <action issue="COLLECTIONS-466" dev="tn" type="update">
       Replaced "Collection" with "Iterable" for method arguments where 
applicable.
     </action>  

Modified: 
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/bag/AbstractMapBag.java
URL: 
http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/bag/AbstractMapBag.java?rev=1491258&r1=1491257&r2=1491258&view=diff
==============================================================================
--- 
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/bag/AbstractMapBag.java
 (original)
+++ 
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/bag/AbstractMapBag.java
 Sun Jun  9 18:35:24 2013
@@ -147,14 +147,14 @@ public abstract class AbstractMapBag<E> 
      * @return <code>true</code> 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;
     }
 
     //-----------------------------------------------------------------------


Reply via email to