mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-07 00:00:13 +02:00
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()`.
This commit is contained in:
+7
-7
@@ -434,13 +434,6 @@ impl Bytes {
|
|||||||
/// Panics if `at > len`.
|
/// Panics if `at > len`.
|
||||||
#[must_use = "consider Bytes::advance if you don't need the other half"]
|
#[must_use = "consider Bytes::advance if you don't need the other half"]
|
||||||
pub fn split_to(&mut self, at: usize) -> Self {
|
pub fn split_to(&mut self, at: usize) -> Self {
|
||||||
assert!(
|
|
||||||
at <= self.len(),
|
|
||||||
"split_to out of bounds: {:?} <= {:?}",
|
|
||||||
at,
|
|
||||||
self.len(),
|
|
||||||
);
|
|
||||||
|
|
||||||
if at == self.len() {
|
if at == self.len() {
|
||||||
return mem::replace(self, Bytes::new());
|
return mem::replace(self, Bytes::new());
|
||||||
}
|
}
|
||||||
@@ -449,6 +442,13 @@ impl Bytes {
|
|||||||
return Bytes::new();
|
return Bytes::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
at <= self.len(),
|
||||||
|
"split_to out of bounds: {:?} <= {:?}",
|
||||||
|
at,
|
||||||
|
self.len(),
|
||||||
|
);
|
||||||
|
|
||||||
let mut ret = self.clone();
|
let mut ret = self.clone();
|
||||||
|
|
||||||
unsafe { self.inc_start(at) };
|
unsafe { self.inc_start(at) };
|
||||||
|
|||||||
Reference in New Issue
Block a user