summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-11-25 19:38:53 +0000
committerPaul Phillips <paulp@improving.org>2009-11-25 19:38:53 +0000
commitdc683cb316800ad82547e0c1ba325cd7f9cb848d (patch)
tree6d66aae46ab51fe93f4ec08d4b3f071f212f0ea5 /src
parent0a1d1a616719022ddaf199db7515207dfc824d3c (diff)
downloadscala-dc683cb316800ad82547e0c1ba325cd7f9cb848d.tar.gz
scala-dc683cb316800ad82547e0c1ba325cd7f9cb848d.tar.bz2
scala-dc683cb316800ad82547e0c1ba325cd7f9cb848d.zip
Cleaning up in scala.runtime.*.
Fixed toArray to copy more than one element into the new one. Added sameElements to Iterator to further simplify the case class support logic, and because it should be there anyway.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/symtab/StdNames.scala1
-rw-r--r--src/library/scala/collection/Iterator.scala15
-rw-r--r--src/library/scala/runtime/ScalaRunTime.scala47
3 files changed, 22 insertions, 41 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/StdNames.scala b/src/compiler/scala/tools/nsc/symtab/StdNames.scala
index 990d6dc463..71d4740cbf 100644
--- a/src/compiler/scala/tools/nsc/symtab/StdNames.scala
+++ b/src/compiler/scala/tools/nsc/symtab/StdNames.scala
@@ -280,7 +280,6 @@ trait StdNames {
val eq = newTermName("eq")
val equals_ = newTermName("equals")
val _equals = newTermName("_equals")
- val _equalsWithVarArgs = newTermName("_equalsWithVarArgs")
val inlinedEquals = newTermName("inlinedEquals")
val error = newTermName("error")
val ex = newTermName("ex")
diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala
index 70462cb8d2..74109a0e81 100644
--- a/src/library/scala/collection/Iterator.scala
+++ b/src/library/scala/collection/Iterator.scala
@@ -14,7 +14,6 @@ package scala.collection
import mutable.{Buffer, ArrayBuffer, ListBuffer, StringBuilder}
import immutable.{List, Stream}
import annotation.{ tailrec }
-// import immutable.{List, Nil, ::, Stream}
/** The <code>Iterator</code> object provides various functions for
* creating specialized iterators.
@@ -1031,6 +1030,20 @@ trait Iterator[+A] { self =>
buffer
}
+ /** Checks if the other iterator contains the same elements as this one.
+ *
+ * @note will not terminate for infinite-sized iterators.
+ * @param that the other iterator
+ * @return true, iff both iterators contain the same elements in the same order.
+ */
+ def sameElements(that: Iterator[_]): Boolean = {
+ while (hasNext && that.hasNext)
+ if (next != that.next)
+ return false
+
+ !hasNext && !that.hasNext
+ }
+
/** Returns a string representation of the elements in this iterator. The resulting string
* begins with the string <code>start</code> and is finished by the string
* <code>end</code>. Inside, the string representations of elements (w.r.t.
diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala
index 79c97af3d7..015d05d62e 100644
--- a/src/library/scala/runtime/ScalaRunTime.scala
+++ b/src/library/scala/runtime/ScalaRunTime.scala
@@ -14,7 +14,7 @@ package scala.runtime
import scala.reflect.ClassManifest
import scala.collection.Seq
import scala.collection.mutable._
-import scala.collection.immutable.{List, Stream, Nil, ::}
+import scala.collection.immutable.{ List, Stream, Nil, :: }
/* The object <code>ScalaRunTime</code> provides ...
*/
@@ -52,7 +52,10 @@ object ScalaRunTime {
def toArray[T](xs: scala.collection.Seq[T]) = {
val arr = new Array[AnyRef](xs.length)
var i = 0
- for (x <- xs) arr(i) = x.asInstanceOf[AnyRef]
+ for (x <- xs) {
+ arr(i) = x.asInstanceOf[AnyRef]
+ i += 1
+ }
arr
}
@@ -87,16 +90,8 @@ object ScalaRunTime {
throw exception
}
- def caseFields(x: Product): List[Any] = {
- val arity = x.productArity
- def fields(from: Int): List[Any] =
- if (from == arity) List()
- else x.productElement(from) :: fields(from + 1)
- fields(0)
- }
-
def _toString(x: Product): String =
- caseFields(x).mkString(x.productPrefix + "(", ",", ")")
+ x.productIterator.mkString(x.productPrefix + "(", ",", ")")
def _hashCodeJenkins(x: Product): Int =
scala.util.JenkinsHash.hashSeq(x.productPrefix.toSeq ++ x.productIterator.toSeq)
@@ -122,36 +117,10 @@ object ScalaRunTime {
else x.equals(y)
def _equals(x: Product, y: Any): Boolean = y match {
- case y1: Product if x.productArity == y1.productArity =>
- val arity = x.productArity
- var i = 0
- while (i < arity && x.productElement(i) == y1.productElement(i))
- i += 1
- i == arity
- case _ =>
- false
+ case y: Product if x.productArity == y.productArity => x.productIterator sameElements y.productIterator
+ case _ => false
}
- def _equalsWithVarArgs(x: Product, y: Any): Boolean = y match {
- case y1: Product if x.productArity == y1.productArity =>
- val arity = x.productArity
- var i = 0
- while (i < arity - 1 && x.productElement(i) == y1.productElement(i))
- i += 1
- i == arity - 1 && {
- x.productElement(i) match {
- case xs: Seq[_] =>
- y1.productElement(i) match {
- case ys: Seq[_] => xs sameElements ys
- }
- }
- }
- case _ =>
- false
- }
-
- def Seq[a](xs: a*): Seq[a] = null // interpreted specially by new backend.
-
/** Given any Scala value, convert it to a String.
*
* The primary motivation for this method is to provide a means for