Skip to content

Commit

Permalink
Use Option and Handle ordering to avoid working with indices.
Browse files Browse the repository at this point in the history
Both `Option` and `Handle` implement `PartialOrd`, and
`Option<Handle<T>>` has the same size as `Handle<T>`, so we can just
do comparisons on `Option<Handle<Expression>>`, and never extract
handle indices.
  • Loading branch information
jimblandy committed Jan 23, 2025
1 parent 1e561b9 commit cd07fdd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions naga/src/compact/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down

0 comments on commit cd07fdd

Please sign in to comment.