Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7bd0630

Browse files
committedMar 12, 2022
Avoid enumerating the iterators in PyArray1::from_slice and ArrayBase::to_pyarray.
1 parent a35b66d commit 7bd0630

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed
 

‎src/array.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -957,9 +957,10 @@ impl<T: Element> PyArray<T, Ix1> {
957957
if T::IS_COPY {
958958
ptr::copy_nonoverlapping(slice.as_ptr(), array.data(), slice.len());
959959
} else {
960-
let data_ptr = array.data();
961-
for (i, item) in slice.iter().enumerate() {
962-
data_ptr.add(i).write(item.clone());
960+
let mut data_ptr = array.data();
961+
for item in slice {
962+
data_ptr.write(item.clone());
963+
data_ptr = data_ptr.add(1);
963964
}
964965
}
965966
array

‎src/convert.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@ where
142142
);
143143
unsafe {
144144
let array = PyArray::<A, _>::new_(py, dim, strides.as_ptr(), 0);
145-
let data_ptr = array.data();
146-
for (i, item) in self.iter().enumerate() {
147-
data_ptr.add(i).write(item.clone());
145+
let mut data_ptr = array.data();
146+
for item in self.iter() {
147+
data_ptr.write(item.clone());
148+
data_ptr = data_ptr.add(1);
148149
}
149150
array
150151
}

0 commit comments

Comments
 (0)
Please sign in to comment.