Skip to content

Commit 9d7ec93

Browse files
authored
[naga] Simplify iterator construction in type_expression_tandem. (#7070)
Rather than reversing two iterators and then zipping them, zip them first and then reverse the result. However, zipped iterators are only reversible if the inputs implement `ExactSizeIterator`, so make `UniqueArena::iter` promise that as well. For consistency, make `Arena::iter` also promise to return an `ExactSizeIterator`.
1 parent dad9d0b commit 9d7ec93

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

naga/src/arena/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<T> Arena<T> {
9494

9595
/// Returns an iterator over the items stored in this arena, returning both
9696
/// the item's handle and a reference to it.
97-
pub fn iter(&self) -> impl DoubleEndedIterator<Item = (Handle<T>, &T)> {
97+
pub fn iter(&self) -> impl DoubleEndedIterator<Item = (Handle<T>, &T)> + ExactSizeIterator {
9898
self.data
9999
.iter()
100100
.enumerate()

naga/src/arena/unique_arena.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<T> Iterator for UniqueArenaDrain<'_, T> {
108108
impl<T: Eq + hash::Hash> UniqueArena<T> {
109109
/// Returns an iterator over the items stored in this arena, returning both
110110
/// the item's handle and a reference to it.
111-
pub fn iter(&self) -> impl DoubleEndedIterator<Item = (Handle<T>, &T)> {
111+
pub fn iter(&self) -> impl DoubleEndedIterator<Item = (Handle<T>, &T)> + ExactSizeIterator {
112112
self.set.iter().enumerate().map(|(i, v)| {
113113
let index = unsafe { Index::new_unchecked(i as u32) };
114114
(Handle::new(index), v)

naga/src/compact/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,9 @@ impl<'module> ModuleTracer<'module> {
303303
// as used by the time we visit it is genuinely unused, and can be
304304
// ignored.
305305
let mut exprs = self.module.global_expressions.iter().rev().peekable();
306-
for ((ty_handle, ty), dep) in self.module.types.iter().rev().zip(max_dep.iter().rev()) {
307-
while let Some((expr_handle, expr)) = exprs.next_if(|&(h, _)| Some(h) > *dep) {
306+
307+
for ((ty_handle, ty), dep) in self.module.types.iter().zip(max_dep).rev() {
308+
while let Some((expr_handle, expr)) = exprs.next_if(|&(h, _)| Some(h) > dep) {
308309
if self.global_expressions_used.contains(expr_handle) {
309310
self.as_const_expression().trace_expression(expr);
310311
}

0 commit comments

Comments
 (0)