summaryrefslogtreecommitdiff
path: root/test/benchmarks/src/scala/collection/parallel/benchmarks/arrays/Arrays.scala
blob: 39232122a9e46f13ca059456389a88f9d89fedc1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package scala.collection.parallel.benchmarks.arrays







object Arrays {
  
  @inline def genericApply[T](xs: Array[T], idx: Int): T = xs.asInstanceOf[AnyRef] match {
    case x: Array[AnyRef] => x(idx).asInstanceOf[T]
    case _ => genericApplyNotAnyRef(xs, idx)
  }
  
  @noinline private def genericApplyNotAnyRef[T](xs: Array[T], idx: Int): T = xs.asInstanceOf[AnyRef] match {
    case x: Array[Int] => x(idx).asInstanceOf[T]
    case x: Array[Double] => x(idx).asInstanceOf[T]
    case x: Array[Long] => x(idx).asInstanceOf[T]
    case x: Array[Float] => x(idx).asInstanceOf[T]
    case x: Array[Char] => x(idx).asInstanceOf[T]
    case x: Array[Byte] => x(idx).asInstanceOf[T]
    case x: Array[Short] => x(idx).asInstanceOf[T]
    case x: Array[Boolean] => x(idx).asInstanceOf[T]
    case x: Array[Unit] => x(idx).asInstanceOf[T]
    case null => throw new NullPointerException
  }
  
  @inline def apply(xs: AnyRef, idx: Int): Any = xs match {
    case x: Array[AnyRef] => x(idx).asInstanceOf[Any]
    case _ => applyNotAnyRef(xs, idx)
  }
  
  @noinline private def applyNotAnyRef(xs: AnyRef, idx: Int): Any = xs match {
    case x: Array[Int] => x(idx).asInstanceOf[Any]
    case x: Array[Double] => x(idx).asInstanceOf[Any]
    case x: Array[Long] => x(idx).asInstanceOf[Any]
    case x: Array[Float] => x(idx).asInstanceOf[Any]
    case x: Array[Char] => x(idx).asInstanceOf[Any]
    case x: Array[Byte] => x(idx).asInstanceOf[Any]
    case x: Array[Short] => x(idx).asInstanceOf[Any]
    case x: Array[Boolean] => x(idx).asInstanceOf[Any]
    case x: Array[Unit] => x(idx).asInstanceOf[Any]
    case null => throw new NullPointerException
  }
  
}