Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions src/dimension/dimension_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,26 +195,32 @@ pub trait Dimension:
#[doc(hidden)]
/// Iteration -- Use self as size, and return next index after `index`
/// or None if there are no more.
// FIXME: use &Self for index or even &mut?
#[inline]
fn next_for(&self, index: Self) -> Option<Self>
fn next_for(&self, mut index: Self) -> Option<Self>
{
if self.next_for_mut(&mut index) {
Some(index)
} else {
None
}
}

#[doc(hidden)]
/// Iteration -- Similar to `next_for`, but addresses the index as mutable reference.
#[inline]
fn next_for_mut(&self, index: &mut Self) -> bool
{
let mut index = index;
let mut done = false;
let mut end_iteration = true;
for (&dim, ix) in zip(self.slice(), index.slice_mut()).rev() {
*ix += 1;
if *ix == dim {
*ix = 0;
} else {
done = true;
end_iteration = false;
break;
}
}
if done {
Some(index)
} else {
None
}
!end_iteration
}

#[doc(hidden)]
Expand Down
8 changes: 5 additions & 3 deletions src/iterators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ impl<A, D: Dimension> Iterator for Baseiter<A, D>
{
let index = match self.index {
None => return None,
Some(ref ix) => ix.clone(),
Some(ref mut ix) => ix,
};
let offset = D::stride_offset(&index, &self.strides);
self.index = self.dim.next_for(index);
let offset = D::stride_offset(index, &self.strides);
if !self.dim.next_for_mut(index) {
self.index = None;
}
unsafe { Some(self.ptr.offset(offset)) }
}

Expand Down
2 changes: 1 addition & 1 deletion src/partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<T> Partial<T>
// covers the whole output.
if left.is_stub() {
right
} else if left.ptr.wrapping_add(left.len) == right.ptr {
} else if ptr::eq(left.ptr.wrapping_add(left.len), right.ptr) {
left.len += right.release_ownership();
left
} else {
Expand Down