summaryrefslogtreecommitdiff
path: root/test/files/specialized
diff options
context:
space:
mode:
authorAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2011-02-09 15:46:50 +0000
committerAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2011-02-09 15:46:50 +0000
commitd34d0d5108542f6eb9ec46acb5daadd5ad4fb7ef (patch)
tree36d3d144fcd65146d0502c048780a993257d38a0 /test/files/specialized
parentd5fbd26715a9084595b605a6b2bfd24cd6f2b66e (diff)
downloadscala-d34d0d5108542f6eb9ec46acb5daadd5ad4fb7ef.tar.gz
scala-d34d0d5108542f6eb9ec46acb5daadd5ad4fb7ef.tar.bz2
scala-d34d0d5108542f6eb9ec46acb5daadd5ad4fb7ef.zip
Added a test case for anyref specialization.
Diffstat (limited to 'test/files/specialized')
-rw-r--r--test/files/specialized/arrays.check4
-rw-r--r--test/files/specialized/arrays.scala55
2 files changed, 59 insertions, 0 deletions
diff --git a/test/files/specialized/arrays.check b/test/files/specialized/arrays.check
new file mode 100644
index 0000000000..d37dfb720d
--- /dev/null
+++ b/test/files/specialized/arrays.check
@@ -0,0 +1,4 @@
+0
+0
+50
+51 \ No newline at end of file
diff --git a/test/files/specialized/arrays.scala b/test/files/specialized/arrays.scala
new file mode 100644
index 0000000000..505f482486
--- /dev/null
+++ b/test/files/specialized/arrays.scala
@@ -0,0 +1,55 @@
+
+
+
+import runtime.ScalaRunTime._
+
+
+class Generic[T](a: Array[T]) {
+ def apply() = a(0)
+}
+
+
+class Spec[@specialized(AnyRef) T](a: Array[T]) {
+ def apply() = a(0)
+}
+
+
+object Test {
+
+ def main(args: Array[String]) {
+ val len = 50
+
+ testSpec(new Array[String](len))
+ println(arrayApplyCount)
+
+ (new Spec(new Array[String](len)))()
+ println(arrayApplyCount)
+
+ testGeneric(new Array[String](len))
+ println(arrayApplyCount)
+
+ (new Generic(new Array[String](len)))()
+ println(arrayApplyCount)
+ }
+
+ def testGeneric[T](a: Array[T]) = {
+ var i = 0
+ var sum = 0
+ while (i < a.length) {
+ sum += (if (a(i) != null) 1 else 0)
+ i += 1
+ }
+ sum
+ }
+
+ def testSpec[@specialized(AnyRef) T](a: Array[T]) = {
+ var i = 0
+ var sum = 0
+ while (i < a.length) {
+ sum += (if (a(i) != null) 1 else 0)
+ i += 1
+ }
+ sum
+ }
+
+}