@@ -71,20 +71,18 @@ private [internal] final class ChainPost(var label: Int) extends InstrWithLabel
7171 // $COVERAGE-ON$
7272}
7373
74- private [internal] final class PreOps (val op : Any => Any , val rest : PreOps )
75- private [internal] object PreOps {
76- val empty : PreOps = null
77- private [instructions] def reduce (ops : PreOps , x : Any ): Any = {
78- if (ops eq empty) x
79- else reduce(ops.rest, ops.op(x))
80- }
74+ private final class AndThen [- A , B , + C ](f : A => B , g : B => C ) extends (A => C ) {
75+ final def apply (x : A ): C = g match {
76+ case g : AndThen [_, _, _] => g(f(x))
77+ case g => g(f(x))
78+ }
8179}
8280
8381private [internal] final class ChainPre (var label : Int ) extends InstrWithLabel {
8482 override def apply (ctx : Context ): Unit = {
8583 if (ctx.good) {
8684 val f = ctx.stack.pop[Any => Any ]()
87- ctx.stack.exchange(new PreOps (f, ctx.stack.peek[PreOps ]))
85+ ctx.stack.exchange(new AndThen (f, ctx.stack.peek[Any => Any ]))
8886 ctx.updateCheckOffset()
8987 ctx.pc = label
9088 }
@@ -99,17 +97,6 @@ private [internal] final class ChainPre(var label: Int) extends InstrWithLabel {
9997 override def toString : String = s " ChainPre( $label) "
10098 // $COVERAGE-ON$
10199}
102- private [internal] object ChainPreReduce extends Instr {
103- override def apply (ctx : Context ): Unit = {
104- ensureRegularInstruction(ctx)
105- val x = ctx.stack.upop()
106- val f = ctx.stack.peek[PreOps ]
107- ctx.exchangeAndContinue(PreOps .reduce(f, x))
108- }
109- // $COVERAGE-OFF$
110- override def toString : String = s " ChainPreReduce "
111- // $COVERAGE-ON$
112- }
113100
114101private [internal] final class Chainl (var label : Int ) extends InstrWithLabel {
115102 override def apply (ctx : Context ): Unit = {
0 commit comments