Skip to content

Commit 36d93ae

Browse files
wetnebWillLillis
authored andcommitted
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).
1 parent 1e7d77c commit 36d93ae

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

crates/generate/src/prepare_grammar/flatten_grammar.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,10 @@ pub(super) fn flatten_grammar(
263263

264264
for (i, variable) in variables.iter().enumerate() {
265265
let symbol = Symbol::non_terminal(i);
266+
let used = symbol_is_used(&variables, symbol);
266267

267268
for production in &variable.productions {
268-
if production.steps.is_empty() && symbol_is_used(&variables, symbol) {
269+
if production.steps.is_empty() && used {
269270
Err(FlattenGrammarError::EmptyString(variable.name.clone()))?;
270271
}
271272

0 commit comments

Comments
 (0)