cats-parse
cats-parse copied to clipboard
alternate design for voiding
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.