diff --git a/benches/eval_expression.rs b/benches/eval_expression.rs index 82fd1b78..b9ac24f2 100644 --- a/benches/eval_expression.rs +++ b/benches/eval_expression.rs @@ -156,3 +156,57 @@ fn bench_eval_loop_strings_no_build(bench: &mut Bencher) { bench.iter(|| engine.consume_ast(&ast).unwrap()); } + +#[bench] +fn bench_eval_switch(bench: &mut Bencher) { + let script = r#" + let sum = 0; + + for x in range(0, 10000) { + sum += switch x % 5 { + 0 => 10, + 1 => 12, + 2 => 42, + 3 => 1, + _ => 9 + } + } + "#; + + let mut engine = Engine::new(); + engine.set_optimization_level(OptimizationLevel::None); + + let ast = engine.compile(script).unwrap(); + + bench.iter(|| engine.consume_ast(&ast).unwrap()); +} + +#[bench] +fn bench_eval_nested_if(bench: &mut Bencher) { + let script = r#" + let sum = 0; + + for x in range(0, 10000) { + let rem = x % 5; + + sum += if rem == 0 { + 10 + } else if rem == 1 { + 12 + } else if rem == 2 { + 42 + } else if rem == 3 { + 1 + } else{ + 9 + }; + } + "#; + + let mut engine = Engine::new(); + engine.set_optimization_level(OptimizationLevel::None); + + let ast = engine.compile(script).unwrap(); + + bench.iter(|| engine.consume_ast(&ast).unwrap()); +} diff --git a/src/parser.rs b/src/parser.rs index 4d6091e3..93d78a89 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2590,7 +2590,7 @@ fn parse_fn( (Token::RightParen, _) => break, (Token::Identifier(s), pos) => { if params.iter().any(|(p, _)| p == &s) { - return Err(PERR::FnDuplicatedParam(name.to_string(), s).into_err(pos)); + return Err(PERR::FnDuplicatedParam(name, s).into_err(pos)); } let s = state.get_interned_string(s); state.stack.push((s.clone(), ScopeEntryType::Normal));