From 973f69ac75507ec602f740b3c291ded2958ea87c Mon Sep 17 00:00:00 2001 From: Rex Kerr Date: Mon, 23 Dec 2013 16:17:40 -0800 Subject: 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.) --- src/library/scala/collection/convert/Wrappers.scala | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/library') diff --git a/src/library/scala/collection/convert/Wrappers.scala b/src/library/scala/collection/convert/Wrappers.scala index 56f1802509..14ae57c43a 100644 --- a/src/library/scala/collection/convert/Wrappers.scala +++ b/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 -- cgit v1.2.3