Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

SI-6364 SetWrapper does not preserve performance / behavior

O(n) performance of wrapped set contains was the problem.

Added overrides for contains and isEmpty to SetWrapper.  Note that sets are
invariant in Scala, while the Java signature is for any Object, so we trap
a ClassCastException if one occurs.  (Is this everything that could possibly
go wrong?  I think so, but am not as confident as I would like.)
  • Loading branch information...
commit 973f69ac75507ec602f740b3c291ded2958ea87c 1 parent b2bf66a
@Ichoran Ichoran authored
Showing with 6 additions and 0 deletions.
  1. +6 −0 src/library/scala/collection/convert/Wrappers.scala
6 src/library/scala/collection/convert/Wrappers.scala
@@ -102,8 +102,14 @@ private[collection] trait Wrappers {
override def clone(): JListWrapper[A] = JListWrapper(new ju.ArrayList[A](underlying))
+ // Note various overrides to avoid performance gotchas.
class SetWrapper[A](underlying: Set[A]) extends ju.AbstractSet[A] {
self =>
+ override def contains(o: Object): Boolean = {
+ try { underlying.contains(o.asInstanceOf[A]) }
+ catch { case cce: ClassCastException => false }
+ }
+ override def isEmpty = underlying.isEmpty
def size = underlying.size
def iterator = new ju.Iterator[A] {
val ui = underlying.iterator
Please sign in to comment.
Something went wrong with that request. Please try again.