perf: More efficient computation of used symbols
As the call to `symbol_is_used` does not depend on the production, it is more efficient to call it only once outside the loop over productions. I'm not sure if `rustc` is able to do this optimization on its own (it would need to know that the function is pure, which sounds difficult in general).
This commit is contained in:
parent
1e7d77c517
commit
36d93aeff3
1 changed files with 2 additions and 1 deletions
|
|
@ -263,9 +263,10 @@ pub(super) fn flatten_grammar(
|
|||
|
||||
for (i, variable) in variables.iter().enumerate() {
|
||||
let symbol = Symbol::non_terminal(i);
|
||||
let used = symbol_is_used(&variables, symbol);
|
||||
|
||||
for production in &variable.productions {
|
||||
if production.steps.is_empty() && symbol_is_used(&variables, symbol) {
|
||||
if production.steps.is_empty() && used {
|
||||
Err(FlattenGrammarError::EmptyString(variable.name.clone()))?;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue