diff options
author | Rex Kerr <ichoran@gmail.com> | 2013-12-23 16:17:40 -0800 |
---|---|---|
committer | Rex Kerr <ichoran@gmail.com> | 2013-12-31 11:48:31 -0800 |
commit | 973f69ac75507ec602f740b3c291ded2958ea87c (patch) | |
tree | 53242348371c0e7ca88fdee8a7498a5ffa5d7bdd /src/library | |
parent | b2bf66a4681dec76281da9469e66e0100ad2709f (diff) | |
download | scala-973f69ac75507ec602f740b3c291ded2958ea87c.tar.gz scala-973f69ac75507ec602f740b3c291ded2958ea87c.tar.bz2 scala-973f69ac75507ec602f740b3c291ded2958ea87c.zip |
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.)
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/collection/convert/Wrappers.scala | 6 |
1 files changed, 6 insertions, 0 deletions
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 |