Review for CR 6728865 : Improved heuristics for Collections.disjoint()
Rémi Forax
forax at univ-mlv.fr
Sat Dec 18 01:02:32 UTC 2010
On 12/18/2010 01:31 AM, Mike Duigou wrote:
> I've posted a webrev for review at
>
> http://cr.openjdk.java.net/~mduigou/6728865.0/webrev/
>
> which improves the behaviour of Collections.disjoint() when the collection c1 is not a Set and is larger than c2.
>
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6728865
>
> I've included some other micro-optimizations suggested by the issue and by common usage.
>
> One optimization, the checks whether either collection is empty using isEmpty(), may slightly degrade performance relative to the current implementation but should be a good tradeoff for cases where either of the collections are empty.
>
> I've also upgraded the javadoc to newer style conventions and included the missing @return.
>
> Any comments or feedback welcome.
>
> Mike
Hi Mike,
I think that comparing size() is not a good idea because
- for some collections, size() is not a constant operation
- you compare size() when c1 and c2 are sets which
may cause a performance regression because
disjoint(treeSet, hashSet) has not the same complexity as
disjoint(hashSet, treeSet).
Otherwise, you declare some local variables final.
Declaring a local variable as final doesn't appear in the generated
bytecode.
The usual convention for the source of the JDK is to use final
in front of a local variable only when needed (inner class).
Rémi
PS: I have also CC JSR 166 list mailing list because I know that Doug
Lea also
maintains patches for package java.util.
More information about the core-libs-dev
mailing list