Currently Parser0 has a private[parse] def parseMut(state: Parser.State): A method. To implement .void we keep track of a mutable var in State and set capturing = false so we can avoid allocation.
An alternate design would be:
private[parse] def parseMut(state: Parser.State): A
private[parse] def parseMutVoid(state: Parser.State): Unit
In this picture, a case class Void(inner: Parser[Any) extends Parser[Unit] would just call parseMutVoid for its parseMut and parseMutVoid. This would potentially do less work since once we convert over to the parseMutVoid we don't check capture again all the way down.
We may or may not have a broad enough set of benchmarks to see a win here, but it may be worth a try.
Currently
Parser0has aprivate[parse] def parseMut(state: Parser.State): Amethod. To implement.voidwe keep track of a mutable var inStateand setcapturing = falseso we can avoid allocation.An alternate design would be:
In this picture, a
case class Void(inner: Parser[Any) extends Parser[Unit]would just callparseMutVoidfor its parseMut and parseMutVoid. This would potentially do less work since once we convert over to theparseMutVoidwe don't checkcaptureagain all the way down.We may or may not have a broad enough set of benchmarks to see a win here, but it may be worth a try.