Skip to content

Commit

Permalink
- fix tailrec for Bytecode.filterNot
Browse files Browse the repository at this point in the history
  • Loading branch information
leclech.patrick committed Jun 10, 2011
1 parent 7eafb64 commit 3a008e3
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions apparat-core/src/main/scala/apparat/bytecode/Bytecode.scala
Expand Up @@ -53,26 +53,25 @@ class Bytecode(var ops: List[AbstractOp], val markers: MarkerManager, var except
}

def filterNot(f: AbstractOp => Boolean) = {
/*@tailrec*/ def loop(list: List[AbstractOp]): List[AbstractOp] = list match {//FIXME make tailrec
@tailrec def loop(list: List[AbstractOp], acc:List[AbstractOp]=Nil): List[AbstractOp] = list match {
case x :: Nil => f(x) match {
case true => {
val nop = Nop()
markers.forwardMarker(x, nop)
nop :: Nil
nop :: acc
}
case false => x :: Nil
case false => x :: acc
}
case x :: xs => f(x) match {
case true => {
markers.forwardMarker(x, xs.head)
loop(xs)
loop(xs, acc)
}
case false => x :: loop(xs)
case false => loop(xs, x :: acc)
}
case Nil => Nil
case _ => acc
}

ops = loop(ops)
ops = loop(ops) reverse
}

def removeAny(op: AbstractOp) = filterNot(_ ~== op)
Expand Down

0 comments on commit 3a008e3

Please sign in to comment.