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 21, 2024
1 parent 851b59b commit 8381ab7
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(self.len, at);
other.len = at;
self.set_start(at);
other
}
Expand Down

0 comments on commit 8381ab7

Please sign in to comment.