Skip to content

Commit

Permalink
remove redundant assertion and min
Browse files Browse the repository at this point in the history
We know several things here:

1. self.len <= self.cap, always
2. at <= self.len, asserted at the top of this method
3. after calling shallow_clone, other.cap == self.cap

Therefore, at <= self.len <= other.cap.
  • Loading branch information
braddunbar committed Jan 22, 2024
1 parent 00a60eb commit 00f2b20
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/bytes_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,8 @@ impl BytesMut {

unsafe {
let mut other = self.shallow_clone();
assert!(at <= other.cap, "set_end out of bounds");

other.cap = at;
other.len = cmp::min(other.len, at);
other.len = at;
self.set_start(at);
other
}
Expand Down

0 comments on commit 00f2b20

Please sign in to comment.