Skip to content

Commit

Permalink
Loop instead of recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Aug 17, 2019
1 parent 2b57a09 commit a52713c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,12 +669,15 @@ impl Compiler {
let original_expr = mem::replace(expr, prelude_expr);

// Replace the 0 in the prelude with the actual expression
fn assign_last_body(l: &mut SpannedExpr<Symbol>, original_expr: SpannedExpr<Symbol>) {
match l.value {
ast::Expr::LetBindings(_, ref mut e) => {
assign_last_body(e, original_expr);
fn assign_last_body(mut l: &mut SpannedExpr<Symbol>, original_expr: SpannedExpr<Symbol>) {
loop {
match l.value {
ast::Expr::LetBindings(_, ref mut e) => l = e,
_ => {
*l = original_expr;
return;
}
}
_ => *l = original_expr,
}
}
assign_last_body(expr, original_expr);
Expand Down

0 comments on commit a52713c

Please sign in to comment.