Skip to content

Commit

Permalink
Use <[T]>::split_at_checked instead of two separate get calls
Browse files Browse the repository at this point in the history
Simplifies the code. Probably allows for more optimized code when
compiling without optimizations. For opt-level=3 the result is the same
as before
  • Loading branch information
faern committed Jul 26, 2024
1 parent a3b1bf9 commit 6d5b9d3
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions src/forward_traffic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,7 @@ fn split_first_datagram(buffer: &[u8]) -> Option<(&[u8], &[u8])> {
let (header, tail) = buffer.split_first_chunk::<HEADER_LEN>()?;
let datagram_len = usize::from(u16::from_be_bytes(*header));

// TODO: These two get calls (and thus double bounds check) can be replaced with
// `split_at_checked` when stabilized: https://github.com/rust-lang/rust/issues/119128
let datagram_data = tail.get(..datagram_len)?;
let tail = tail.get(datagram_len..)?;

Some((datagram_data, tail))
tail.split_at_checked(datagram_len)

Check failure on line 130 in src/forward_traffic.rs

View workflow job for this annotation

GitHub Actions / clippy

current MSRV (Minimum Supported Rust Version) is `1.77.0` but this item is stable since `1.80.0`

error: current MSRV (Minimum Supported Rust Version) is `1.77.0` but this item is stable since `1.80.0` --> src/forward_traffic.rs:130:10 | 130 | tail.split_at_checked(datagram_len) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv note: the lint level is defined here --> src/lib.rs:82:9 | 82 | #![deny(clippy::all)] | ^^^^^^^^^^^ = note: `#[deny(clippy::incompatible_msrv)]` implied by `#[deny(clippy::all)]`
}

/// Reads datagrams from `udp_in` and writes them (with the 16 bit header containing the length)
Expand Down

0 comments on commit 6d5b9d3

Please sign in to comment.