perf: don't clone the pest iterator when parsing

Signed-off-by: ljedrz <ljedrz@gmail.com>
This commit is contained in:
ljedrz 2020-10-21 11:12:25 +02:00
parent 61556cca29
commit 5fbbf5e978

View File

@ -159,12 +159,11 @@ impl<'ast> FromPest<'ast> for Expression<'ast> {
type Rule = Rule;
fn from_pest(pest: &mut Pairs<'ast, Rule>) -> Result<Self, ConversionError<Void>> {
let mut clone = pest.clone();
let pair = clone.next().ok_or(::from_pest::ConversionError::NoMatch)?;
let pair = pest.peek().ok_or(::from_pest::ConversionError::NoMatch)?;
match pair.as_rule() {
Rule::expression => {
// Transfer iterated state to pest.
*pest = clone;
// advance the iterator
pest.next();
Ok(PRECEDENCE_CLIMBER.climb(pair.into_inner(), parse_term, binary_expression))
}
_ => Err(ConversionError::NoMatch),