diff --git a/core/src/main/scala/org/apache/spark/util/collection/OpenHashSet.scala b/core/src/main/scala/org/apache/spark/util/collection/OpenHashSet.scala index 6815e47a198d9..faee9ce56a0a1 100644 --- a/core/src/main/scala/org/apache/spark/util/collection/OpenHashSet.scala +++ b/core/src/main/scala/org/apache/spark/util/collection/OpenHashSet.scala @@ -62,28 +62,12 @@ class OpenHashSet[@specialized(Long, Int, Double, Float) T: ClassTag]( // specialization to work (specialized class extends the non-specialized one and needs access // to the "private" variables). - protected val hasher: Hasher[T] = { - // It would've been more natural to write the following using pattern matching. But Scala 2.9.x - // compiler has a bug when specialization is used together with this pattern matching, and - // throws: - // scala.tools.nsc.symtab.Types$TypeError: type mismatch; - // found : scala.reflect.AnyValManifest[Long] - // required: scala.reflect.ClassTag[Int] - // at scala.tools.nsc.typechecker.Contexts$Context.error(Contexts.scala:298) - // at scala.tools.nsc.typechecker.Infer$Inferencer.error(Infer.scala:207) - // ... - val mt = classTag[T] - if (mt == ClassTag.Long) { - (new LongHasher).asInstanceOf[Hasher[T]] - } else if (mt == ClassTag.Int) { - (new IntHasher).asInstanceOf[Hasher[T]] - } else if (mt == ClassTag.Double) { - (new DoubleHasher).asInstanceOf[Hasher[T]] - } else if (mt == ClassTag.Float) { - (new FloatHasher).asInstanceOf[Hasher[T]] - } else { - new Hasher[T] - } + protected val hasher: Hasher[T] = classTag[T] match { + case ClassTag.Long => new LongHasher().asInstanceOf[Hasher[T]] + case ClassTag.Int => new IntHasher().asInstanceOf[Hasher[T]] + case ClassTag.Double => new DoubleHasher().asInstanceOf[Hasher[T]] + case ClassTag.Float => new FloatHasher().asInstanceOf[Hasher[T]] + case _ => new Hasher[T] } protected var _capacity = nextPowerOf2(initialCapacity)