Commit 2234ceee authored by Jeff Smits's avatar Jeff Smits

Simplified matching against lists, no intermediate vector allocation

parent db7bae55
......@@ -332,21 +332,16 @@ fn eval_match<'d, 'f: 'd>(
.ok_or(Error::StrategyFailed)
}
Op("Cons", ref children) if children.len() == 2 => {
current.get_list().ok_or(Error::StrategyFailed).and_then(
|v| {
if v.is_empty() {
Err(Error::StrategyFailed)
} else {
eval_match(context, &children[0], &v[0])?;
let tail = if v.len() > 1 {
context.factory.list(v.into_iter().skip(1))
} else {
context.factory.nil()
};
eval_match(context, &children[1], &tail)
}
match current.term {
::factory::Term::List(ref r) => match **r {
::factory::TermList::Cons(ref head, ref tail) => {
eval_match(context, &children[0], head)?;
eval_match(context, &children[1], &context.factory.list_term(tail.clone()))
},
::factory::TermList::Nil => Err(Error::StrategyFailed),
},
)
_ => Err(Error::StrategyFailed),
}
}
Op("Nil", ref children) if children.is_empty() => {
current
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment