Remove use of unsafe for CsLaneIterMut
This commit is contained in:
parent
b59c4a3216
commit
e261e7c388
|
@ -3,7 +3,7 @@ use crate::{SparseEntry, SparseEntryMut};
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use std::ptr::slice_from_raw_parts_mut;
|
use std::mem::replace;
|
||||||
|
|
||||||
/// An abstract compressed matrix.
|
/// An abstract compressed matrix.
|
||||||
///
|
///
|
||||||
|
@ -238,7 +238,7 @@ pub struct CsLaneIterMut<'a, T> {
|
||||||
// The index of the lane that will be returned on the next iteration
|
// The index of the lane that will be returned on the next iteration
|
||||||
current_lane_idx: usize,
|
current_lane_idx: usize,
|
||||||
pattern: &'a SparsityPattern,
|
pattern: &'a SparsityPattern,
|
||||||
remaining_values: *mut T,
|
remaining_values: &'a mut [T],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T> CsLaneIterMut<'a, T> {
|
impl<'a, T> CsLaneIterMut<'a, T> {
|
||||||
|
@ -246,7 +246,7 @@ impl<'a, T> CsLaneIterMut<'a, T> {
|
||||||
Self {
|
Self {
|
||||||
current_lane_idx: 0,
|
current_lane_idx: 0,
|
||||||
pattern,
|
pattern,
|
||||||
remaining_values: values.as_mut_ptr()
|
remaining_values: values
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -264,12 +264,9 @@ impl<'a, T> Iterator for CsLaneIterMut<'a, T>
|
||||||
if let Some(minor_indices) = lane {
|
if let Some(minor_indices) = lane {
|
||||||
let count = minor_indices.len();
|
let count = minor_indices.len();
|
||||||
|
|
||||||
// Note: I can't think of any way to construct this iterator without unsafe.
|
let remaining = replace(&mut self.remaining_values, &mut []);
|
||||||
let values_in_lane;
|
let (values_in_lane, remaining) = remaining.split_at_mut(count);
|
||||||
unsafe {
|
self.remaining_values = remaining;
|
||||||
values_in_lane = &mut *slice_from_raw_parts_mut(self.remaining_values, count);
|
|
||||||
self.remaining_values = self.remaining_values.add(count);
|
|
||||||
}
|
|
||||||
self.current_lane_idx += 1;
|
self.current_lane_idx += 1;
|
||||||
|
|
||||||
Some(CsLaneMut {
|
Some(CsLaneMut {
|
||||||
|
|
Loading…
Reference in New Issue