Skip to content

Commit 4eb62b9

Browse files
authored
Bytes::split_to - check fast path first (#689)
If `at == self.len()` then we already know `at <= self.len()`. If `at == 0`, it can't be greater than `self.len()`.
1 parent e4af486 commit 4eb62b9

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
@@ -434,13 +434,6 @@ impl Bytes {
434434
/// Panics if `at > len`.
435435
#[must_use = "consider Bytes::advance if you don't need the other half"]
436436
pub fn split_to(&mut self, at: usize) -> Self {
437-
assert!(
438-
at <= self.len(),
439-
"split_to out of bounds: {:?} <= {:?}",
440-
at,
441-
self.len(),
442-
);
443-
444437
if at == self.len() {
445438
return mem::replace(self, Bytes::new());
446439
}
@@ -449,6 +442,13 @@ impl Bytes {
449442
return Bytes::new();
450443
}
451444

445+
assert!(
446+
at <= self.len(),
447+
"split_to out of bounds: {:?} <= {:?}",
448+
at,
449+
self.len(),
450+
);
451+
452452
let mut ret = self.clone();
453453

454454
unsafe { self.inc_start(at) };

0 commit comments

Comments
 (0)