Skip to content

Commit

Permalink
Tweak Array::concat (#112)
Browse files Browse the repository at this point in the history
This approach simplifies the method code and removes
`arithmetic_side_effects` warning while resulting in the same assembly.
  • Loading branch information
newpavlov authored Jan 10, 2025
1 parent 03b3c79 commit 967fdee
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,22 +226,19 @@ where

/// Concatenates `self` with `other`.
#[inline]
#[allow(clippy::arithmetic_side_effects, reason = "`i` will never overflow")]
pub fn concat<N>(self, other: Array<T, N>) -> Array<T, Sum<U, N>>
where
N: ArraySize,
U: Add<N>,
Sum<U, N>: ArraySize,
{
let mut c = Array::uninit();
let mut i = 0;
for v in self {
c[i].write(v);
i += 1;
let (left, right) = c.split_at_mut(self.len());
for (val, dst) in self.into_iter().zip(left) {
dst.write(val);
}
for v in other {
c[i].write(v);
i += 1;
for (val, dst) in other.into_iter().zip(right) {
dst.write(val);
}
// SAFETY: We wrote to every element of `c`.
unsafe { c.assume_init() }
Expand Down

0 comments on commit 967fdee

Please sign in to comment.