From d5763d58d993be554b5f19ab9b13992f903e3ad3 Mon Sep 17 00:00:00 2001 From: David MacIver Date: Tue, 28 Oct 2008 01:06:18 +0000 Subject: Random hygiene: - converting from Iterator to Iterable - Squashing of while loops - A few minor changes. --- .../tools/nsc/matching/ParallelMatching.scala | 23 ++++++++++------------ .../scala/tools/nsc/matching/PatternNodes.scala | 11 ++++------- 2 files changed, 14 insertions(+), 20 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala index 385b00b455..1461cd7098 100644 --- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala +++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala @@ -164,7 +164,7 @@ trait ParallelMatching { val r @ Row(_,s,_,_) = rest.row(index) if (defaultV.isEmpty) r else { val vs = strip1(column(index)) // get vars - r.insert2(Nil, s.add(vs.elements, scrutinee)) + r.insert2(Nil, s.add(vs, scrutinee)) } } @@ -203,7 +203,7 @@ trait ParallelMatching { override def grabRow(index: Int) = { val firstValue = tagIndices(tagIndices.firstKey).head val r @ Row(_,s,_,_) = rest.row(firstValue) - val nbindings = s.add(strip1(column(index)).elements, scrutinee) + val nbindings = s.add(strip1(column(index)), scrutinee) r.insert2(List(column(firstValue)), nbindings) } @@ -259,7 +259,7 @@ trait ParallelMatching { private def bindVars(Tag:Int, orig: Binding): Binding = { def myBindVars(rest:List[(Int,List[Symbol])], bnd: Binding): Binding = rest match { case Nil => bnd - case (Tag,vs)::xs => myBindVars(xs, bnd.add(vs.elements, scrutinee)) + case (Tag,vs)::xs => myBindVars(xs, bnd.add(vs, scrutinee)) case (_, vs)::xs => myBindVars(xs, bnd) } myBindVars(varMap, orig) @@ -341,7 +341,7 @@ trait ParallelMatching { val nrows = column.zip(rest.row) map { case (pat, r) => strip2(pat) match { case sameUnapplyCall(args) => - r.insert2(List(EmptyTree), r.subst.add(strip1(pat).elements, scrutinee)) + r.insert2(List(EmptyTree), r.subst.add(strip1(pat), scrutinee)) case _ => r.insert(pat) }} @@ -354,7 +354,7 @@ trait ParallelMatching { val nrows = column.zip(rest.row) map { case (pat, r: Row) => strip2(pat) match { case sameUnapplyCall(args) => - val nsubst = r.subst.add(strip1(pat).elements, scrutinee) + val nsubst = r.subst.add(strip1(pat), scrutinee) r.insert2(List(args(0), EmptyTree), nsubst) case _ => r.insert(List(EmptyTree, pat)) @@ -381,7 +381,7 @@ trait ParallelMatching { val nrows = column.zip(rest.row) map { case (pat, r: Row) => strip2(pat) match { case sameUnapplyCall(args) => - val nsubst = r.subst.add(strip1(pat).elements, scrutinee) + val nsubst = r.subst.add(strip1(pat), scrutinee) r.insert2(args ::: List(EmptyTree), nsubst) case _ => r.insert(dummies ::: List(pat)) @@ -519,7 +519,7 @@ trait ParallelMatching { } assert(vlue.tpe ne null, "value tpe is null") val vs = strip1(column.head) - val nsuccFst = rest.row.head match { case r: Row => r.insert2(List(EmptyTree), r.subst.add(vs.elements, scrutinee)) } + val nsuccFst = rest.row.head match { case r: Row => r.insert2(List(EmptyTree), r.subst.add(vs, scrutinee)) } val fLabel = theOwner.newLabel(scrutinee.pos, cunit.fresh.newName(scrutinee.pos, "failCont%")) // warning, untyped val sx = rep.shortCut(fLabel) // register shortcut val nsuccRow = nsuccFst :: Row(getDummies( 1 /*scrutinee*/ + rest.temp.length), NoBinding, EmptyTree, sx) :: Nil @@ -600,9 +600,8 @@ trait ParallelMatching { /*init block*/ { var sr = (moreSpecific,subsumed,remaining) - var j = 0; var pats = column; while(pats ne Nil) { + for ((pat, j) <- column.zipWithIndex){ val (ms,ss,rs) = sr // more specific, more general(subsuming current), remaining patterns - val pat = pats.head val strippedPattern = strip2(pat) val patternType = strippedPattern.tpe sr = strippedPattern match { @@ -629,8 +628,6 @@ trait ParallelMatching { case _ => (ms,ss,(j,pat)::rs) } - j += 1 - pats = pats.tail } this.moreSpecific = sr._1.reverse this.subsumed = sr._2.reverse @@ -668,7 +665,7 @@ trait ParallelMatching { case (j, pats) => val (vs, thePat) = strip(column(j)) val r = rest.row(j) - val nsubst = r.subst.add(vs.elements, casted) + val nsubst = r.subst.add(vs, casted) r.insert2(pats, nsubst) } rep.make(ntemps, ntriples) @@ -1110,7 +1107,7 @@ trait ParallelMatching { var px = 0; var rpats = pats; var bnd = subst; var temps = temp; while((bnd ne null) && (rpats ne Nil)) { val (vs,p) = strip(rpats.head); if (!isDefaultPattern(p)) { /*break*/ bnd = null; } else { - bnd = bnd.add(vs.elements,temps.head) + bnd = bnd.add(vs,temps.head) rpats = rpats.tail temps = temps.tail px += 1 // pattern index diff --git a/src/compiler/scala/tools/nsc/matching/PatternNodes.scala b/src/compiler/scala/tools/nsc/matching/PatternNodes.scala index fe16cc9285..d1208c92a0 100644 --- a/src/compiler/scala/tools/nsc/matching/PatternNodes.scala +++ b/src/compiler/scala/tools/nsc/matching/PatternNodes.scala @@ -152,13 +152,10 @@ trait PatternNodes { self: transform.ExplicitOuter => * temp: the temp variable that holds the actual value * next: next binding */ - case class Binding(pvar:Symbol, temp:Symbol, next: Binding) extends Function1[Symbol, Ident]{ - def add(vs:Iterator[Symbol], temp:Symbol): Binding = { - var b = this; while(vs.hasNext){ - b = Binding(vs.next, temp, b) - } - return b - } + case class Binding(pvar:Symbol, temp:Symbol, private val next: Binding) extends Function1[Symbol, Ident]{ + def add(vs : Iterable[Symbol], temp : Symbol): Binding = + vs.foldLeft(this)((x, y) => Binding(y, temp, x)) + /** this is just to produce debug output, ListBuffer needs an equals method?! */ override def equals(x:Any) = { x match { -- cgit v1.2.3