diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-10-24 10:37:14 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-10-24 10:37:14 -0700 |
commit | 24d05696bf53d492b0864918ad1b013897f9f1d6 (patch) | |
tree | 417be4878237d22823ffaa280d35e949807c635e /src | |
parent | a055b1baabccf00f3b2479c818fbf9b44ea472ba (diff) | |
parent | f38f762fc645ad24f5c9a297a6e62a75e9fa4b94 (diff) | |
download | scala-24d05696bf53d492b0864918ad1b013897f9f1d6.tar.gz scala-24d05696bf53d492b0864918ad1b013897f9f1d6.tar.bz2 scala-24d05696bf53d492b0864918ad1b013897f9f1d6.zip |
Merge pull request #3006 from ivmaykov/master
SI-7883 - don't iterate over all keys in MapWrapper.containsKey()
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/convert/Wrappers.scala | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/library/scala/collection/convert/Wrappers.scala b/src/library/scala/collection/convert/Wrappers.scala index 4410ddc7d8..56f1802509 100644 --- a/src/library/scala/collection/convert/Wrappers.scala +++ b/src/library/scala/collection/convert/Wrappers.scala @@ -212,6 +212,15 @@ private[collection] trait Wrappers { } } } + + override def containsKey(key: AnyRef): Boolean = try { + // Note: Subclass of collection.Map with specific key type may redirect generic + // contains to specific contains, which will throw a ClassCastException if the + // wrong type is passed. This is why we need a type cast to A inside a try/catch. + underlying.contains(key.asInstanceOf[A]) + } catch { + case ex: ClassCastException => false + } } case class MutableMapWrapper[A, B](underlying: mutable.Map[A, B]) extends MapWrapper[A, B](underlying) { |