From 4ebe14a9f0c880783bc00b9d8d40824796f6e4b5 Mon Sep 17 00:00:00 2001 From: Adam Kern Date: Sun, 15 Feb 2026 11:50:43 -0500 Subject: [PATCH 1/2] Use `take` in iteration to avoid a clone --- src/dimension/dimension_trait.rs | 3 +-- src/iterators/mod.rs | 7 ++----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/dimension/dimension_trait.rs b/src/dimension/dimension_trait.rs index 3544a7f3c..373edb35e 100644 --- a/src/dimension/dimension_trait.rs +++ b/src/dimension/dimension_trait.rs @@ -197,9 +197,8 @@ pub trait Dimension: /// or None if there are no more. // FIXME: use &Self for index or even &mut? #[inline] - fn next_for(&self, index: Self) -> Option + fn next_for(&self, mut index: Self) -> Option { - let mut index = index; let mut done = false; for (&dim, ix) in zip(self.slice(), index.slice_mut()).rev() { *ix += 1; diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index f7892a8c9..dd3036301 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -18,8 +18,8 @@ mod windows; use alloc::vec::Vec; use std::iter::FromIterator; use std::marker::PhantomData; -use std::ptr; use std::ptr::NonNull; +use std::{mem, ptr}; #[allow(unused_imports)] // Needed for Rust 1.64 use rawpointer::PointerExt; @@ -72,10 +72,7 @@ impl Iterator for Baseiter #[inline] fn next(&mut self) -> Option { - let index = match self.index { - None => return None, - Some(ref ix) => ix.clone(), - }; + let index = self.index.take()?; let offset = D::stride_offset(&index, &self.strides); self.index = self.dim.next_for(index); unsafe { Some(self.ptr.offset(offset)) } From 777cbd67748f1f7482c0afc2ccca6cdb2312cfc9 Mon Sep 17 00:00:00 2001 From: Adam Kern Date: Sun, 15 Feb 2026 11:51:17 -0500 Subject: [PATCH 2/2] Remove unused import --- src/iterators/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index dd3036301..abca3579d 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -18,8 +18,8 @@ mod windows; use alloc::vec::Vec; use std::iter::FromIterator; use std::marker::PhantomData; +use std::ptr; use std::ptr::NonNull; -use std::{mem, ptr}; #[allow(unused_imports)] // Needed for Rust 1.64 use rawpointer::PointerExt;