From a326f40dbf25e50976d17a3a90bdd2dc5e37a87e Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 21 Dec 2009 17:30:23 +0000 Subject: (1) Added some classes to allow arbitrary patch... (1) Added some classes to allow arbitrary patches to source buffers. (These are not yet complete so do not need a review yet I think. (2) Avoided reflexive array operations in ScalaRunTime. review by (community. --- src/library/scala/runtime/ScalaRunTime.scala | 42 ++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'src/library') diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala index f6c4cf79dc..ecc81c074e 100644 --- a/src/library/scala/runtime/ScalaRunTime.scala +++ b/src/library/scala/runtime/ScalaRunTime.scala @@ -30,13 +30,49 @@ object ScalaRunTime { def isValueClass(clazz: Class[_]) = clazz.isPrimitive() /** Retrieve generic array element */ - def array_apply(xs: AnyRef, idx: Int): Any = java.lang.reflect.Array.get(xs, idx) + def array_apply(xs: AnyRef, idx: Int): Any = xs match { + case x: Array[AnyRef] => x(idx).asInstanceOf[Any] + 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 + } /** update generic array element */ - def array_update(xs: AnyRef, idx: Int, value: Any): Unit = java.lang.reflect.Array.set(xs, idx, value) + def array_update(xs: AnyRef, idx: Int, value: Any): Unit = xs match { + case x: Array[AnyRef] => x(idx) = value.asInstanceOf[AnyRef] + case x: Array[Int] => x(idx) = value.asInstanceOf[Int] + case x: Array[Double] => x(idx) = value.asInstanceOf[Double] + case x: Array[Long] => x(idx) = value.asInstanceOf[Long] + case x: Array[Float] => x(idx) = value.asInstanceOf[Float] + case x: Array[Char] => x(idx) = value.asInstanceOf[Char] + case x: Array[Byte] => x(idx) = value.asInstanceOf[Byte] + case x: Array[Short] => x(idx) = value.asInstanceOf[Short] + case x: Array[Boolean] => x(idx) = value.asInstanceOf[Boolean] + case x: Array[Unit] => x(idx) = value.asInstanceOf[Unit] + case null => throw new NullPointerException + } /** Get generic array length */ - def array_length(xs: AnyRef): Int = java.lang.reflect.Array.getLength(xs) + def array_length(xs: AnyRef): Int = xs match { + case x: Array[AnyRef] => x.length + case x: Array[Int] => x.length + case x: Array[Double] => x.length + case x: Array[Long] => x.length + case x: Array[Float] => x.length + case x: Array[Char] => x.length + case x: Array[Byte] => x.length + case x: Array[Short] => x.length + case x: Array[Boolean] => x.length + case x: Array[Unit] => x.length + case null => throw new NullPointerException + } /** Convert a numeric value array to an object array. * Needed to deal with vararg arguments of primtive types that are passed -- cgit v1.2.3