-
Type:
Enhancement
-
Resolution: Unresolved
-
Priority:
P4
-
None
-
Affects Version/s: 15
-
Component/s: core-libs
A DESCRIPTION OF THE PROBLEM :
add to the beginning of the function
java.util.Collections.disjoint(Collection<?> c1, Collection<?> c2)
if(c1 == c2) return false; // same collection. All match
if (c1.isEmpty() || c2.isEmpty()) return true; // At least one collection is empty. Nothing will match.
Justification:
This small minor changes will easily improve run-time.
Specially for the case of (c1 instanceof Set) && (c1.isEmpty()). In which case:
iterate = c2;
contains = c1;
and then we perform O(c2.size()) unnecessary operations of
for (Object e : iterate)
which is surly to be false for contains.contains(e), as variable contains (contains == c1) is empty.
add to the beginning of the function
java.util.Collections.disjoint(Collection<?> c1, Collection<?> c2)
if(c1 == c2) return false; // same collection. All match
if (c1.isEmpty() || c2.isEmpty()) return true; // At least one collection is empty. Nothing will match.
Justification:
This small minor changes will easily improve run-time.
Specially for the case of (c1 instanceof Set) && (c1.isEmpty()). In which case:
iterate = c2;
contains = c1;
and then we perform O(c2.size()) unnecessary operations of
for (Object e : iterate)
which is surly to be false for contains.contains(e), as variable contains (contains == c1) is empty.