Skip to content

Commit 68c5be0

Browse files
committed
append: Avoid cloning dim values where possible
While this has no effect for low-dimensionality arrays, for dyn dim it can save some time.
1 parent cae2544 commit 68c5be0

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/impl_owned_array.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -396,18 +396,19 @@ impl<A, D> Array<A, D>
396396
}
397397

398398
let current_axis_len = self.len_of(axis);
399-
let remaining_shape = self.raw_dim().remove_axis(axis);
400-
let array_rem_shape = array.raw_dim().remove_axis(axis);
399+
let self_dim = self.raw_dim();
400+
let array_dim = array.raw_dim();
401+
let remaining_shape = self_dim.remove_axis(axis);
402+
let array_rem_shape = array_dim.remove_axis(axis);
401403

402404
if remaining_shape != array_rem_shape {
403405
return Err(ShapeError::from_kind(ErrorKind::IncompatibleShape));
404406
}
405407

406408
let len_to_append = array.len();
407409

408-
let array_shape = array.raw_dim();
409-
let mut res_dim = self.raw_dim();
410-
res_dim[axis.index()] += array_shape[axis.index()];
410+
let mut res_dim = self_dim;
411+
res_dim[axis.index()] += array_dim[axis.index()];
411412
let new_len = dimension::size_of_shape_checked(&res_dim)?;
412413

413414
if len_to_append == 0 {
@@ -526,7 +527,7 @@ impl<A, D> Array<A, D>
526527

527528
// With > 0 strides, the current end of data is the correct base pointer for tail_view
528529
let tail_ptr = self.data.as_end_nonnull();
529-
let mut tail_view = RawArrayViewMut::new(tail_ptr, array_shape, tail_strides);
530+
let mut tail_view = RawArrayViewMut::new(tail_ptr, array_dim, tail_strides);
530531

531532
if tail_view.ndim() > 1 {
532533
sort_axes_in_default_order_tandem(&mut tail_view, &mut array);

0 commit comments

Comments
 (0)