From cd07fdd3257ee2c1653052c289536d663435a046 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Wed, 22 Jan 2025 19:44:33 -0800 Subject: [PATCH] Use Option and Handle ordering to avoid working with indices. Both `Option` and `Handle` implement `PartialOrd`, and `Option>` has the same size as `Handle`, so we can just do comparisons on `Option>`, and never extract handle indices. --- naga/src/compact/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/naga/src/compact/mod.rs b/naga/src/compact/mod.rs index 82e202fc09..ef41a611cb 100644 --- a/naga/src/compact/mod.rs +++ b/naga/src/compact/mod.rs @@ -270,7 +270,7 @@ impl<'module> ModuleTracer<'module> { // forward scan of the type arena. The rules further imply that T can // only be referred to by expressions after E. let mut max_dep = Vec::with_capacity(self.module.types.len()); - let mut previous = 0; + let mut previous = None; for (_handle, ty) in self.module.types.iter() { previous = std::cmp::max( previous, @@ -283,8 +283,8 @@ impl<'module> ModuleTracer<'module> { | crate::TypeInner::BindingArray { base: _, size: crate::ArraySize::Pending(crate::PendingArraySize::Expression(expr)), - } => expr.index(), - _ => 0, + } => Some(expr), + _ => None, }, ); max_dep.push(previous); @@ -304,7 +304,7 @@ impl<'module> ModuleTracer<'module> { // ignored. let mut exprs = self.module.global_expressions.iter().rev().peekable(); for ((ty_handle, ty), dep) in self.module.types.iter().rev().zip(max_dep.iter().rev()) { - while let Some((expr_handle, expr)) = exprs.next_if(|&(h, _)| h.index() > *dep) { + while let Some((expr_handle, expr)) = exprs.next_if(|&(h, _)| Some(h) > *dep) { if self.global_expressions_used.contains(expr_handle) { self.as_const_expression().trace_expression(expr); }