[naga] Hoist ConstantEvaluator construction in process_function.

There's no need to build a fresh `ConstantEvaluator` for every
expression; just build it once and reuse it.
This commit is contained in:
Jim Blandy 2024-03-23 07:53:39 -07:00 committed by Teodor Tanasoaia
parent f464598646
commit aaf3b17623

View File

@ -282,18 +282,18 @@ fn process_function(
let mut emitter = Emitter::default(); let mut emitter = Emitter::default();
let mut block = Block::new(); let mut block = Block::new();
for (old_h, expr, span) in expressions.drain() { let mut evaluator = ConstantEvaluator::for_wgsl_function(
let mut expr = match expr { module,
Expression::Override(h) => Expression::Constant(override_map[h.index()]), &mut function.expressions,
expr => expr, &mut local_expression_kind_tracker,
}; &mut emitter,
let mut evaluator = ConstantEvaluator::for_wgsl_function( &mut block,
module, );
&mut function.expressions,
&mut local_expression_kind_tracker, for (old_h, mut expr, span) in expressions.drain() {
&mut emitter, if let Expression::Override(h) = expr {
&mut block, expr = Expression::Constant(override_map[h.index()]);
); }
adjust_expr(&adjusted_local_expressions, &mut expr); adjust_expr(&adjusted_local_expressions, &mut expr);
let h = evaluator.try_eval_and_append(expr, span)?; let h = evaluator.try_eval_and_append(expr, span)?;
debug_assert_eq!(old_h.index(), adjusted_local_expressions.len()); debug_assert_eq!(old_h.index(), adjusted_local_expressions.len());