Skip to content

Commit ce09d7d

Browse files
authored
Bytes::split_off - check fast path first (#693)
Follow up to #689 * If `at == self.len()`, we already know `at <= self.len()`. * If `at == 0`, we already know `at <= self.len()`.
1 parent 9d3ec1c commit ce09d7d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/bytes.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,13 +385,6 @@ impl Bytes {
385385
/// Panics if `at > len`.
386386
#[must_use = "consider Bytes::truncate if you don't need the other half"]
387387
pub fn split_off(&mut self, at: usize) -> Self {
388-
assert!(
389-
at <= self.len(),
390-
"split_off out of bounds: {:?} <= {:?}",
391-
at,
392-
self.len(),
393-
);
394-
395388
if at == self.len() {
396389
return Bytes::new();
397390
}
@@ -400,6 +393,13 @@ impl Bytes {
400393
return mem::replace(self, Bytes::new());
401394
}
402395

396+
assert!(
397+
at <= self.len(),
398+
"split_off out of bounds: {:?} <= {:?}",
399+
at,
400+
self.len(),
401+
);
402+
403403
let mut ret = self.clone();
404404

405405
self.len = at;

0 commit comments

Comments
 (0)