Skip to content

Commit

Permalink
Bytes::split_off - check fast path first (#693)
Browse files Browse the repository at this point in the history
Follow up to #689

* If `at == self.len()`, we already know `at <= self.len()`.
* If `at == 0`, we already know `at <= self.len()`.
  • Loading branch information
braddunbar authored Apr 24, 2024
1 parent 9d3ec1c commit ce09d7d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,6 @@ impl Bytes {
/// Panics if `at > len`.
#[must_use = "consider Bytes::truncate if you don't need the other half"]
pub fn split_off(&mut self, at: usize) -> Self {
assert!(
at <= self.len(),
"split_off out of bounds: {:?} <= {:?}",
at,
self.len(),
);

if at == self.len() {
return Bytes::new();
}
Expand All @@ -400,6 +393,13 @@ impl Bytes {
return mem::replace(self, Bytes::new());
}

assert!(
at <= self.len(),
"split_off out of bounds: {:?} <= {:?}",
at,
self.len(),
);

let mut ret = self.clone();

self.len = at;
Expand Down

0 comments on commit ce09d7d

Please sign in to comment.