Skip to content

Commit 4ebe14a

Browse files
committed
Use take in iteration to avoid a clone
1 parent fd67f70 commit 4ebe14a

2 files changed

Lines changed: 3 additions & 7 deletions

File tree

src/dimension/dimension_trait.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,8 @@ pub trait Dimension:
197197
/// or None if there are no more.
198198
// FIXME: use &Self for index or even &mut?
199199
#[inline]
200-
fn next_for(&self, index: Self) -> Option<Self>
200+
fn next_for(&self, mut index: Self) -> Option<Self>
201201
{
202-
let mut index = index;
203202
let mut done = false;
204203
for (&dim, ix) in zip(self.slice(), index.slice_mut()).rev() {
205204
*ix += 1;

src/iterators/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ mod windows;
1818
use alloc::vec::Vec;
1919
use std::iter::FromIterator;
2020
use std::marker::PhantomData;
21-
use std::ptr;
2221
use std::ptr::NonNull;
22+
use std::{mem, ptr};
2323

2424
#[allow(unused_imports)] // Needed for Rust 1.64
2525
use rawpointer::PointerExt;
@@ -72,10 +72,7 @@ impl<A, D: Dimension> Iterator for Baseiter<A, D>
7272
#[inline]
7373
fn next(&mut self) -> Option<Self::Item>
7474
{
75-
let index = match self.index {
76-
None => return None,
77-
Some(ref ix) => ix.clone(),
78-
};
75+
let index = self.index.take()?;
7976
let offset = D::stride_offset(&index, &self.strides);
8077
self.index = self.dim.next_for(index);
8178
unsafe { Some(self.ptr.offset(offset)) }

0 commit comments

Comments
 (0)