mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-25 00:00:22 +02:00
Bytes::split_off - check fast path first (#693)
Follow up to https://github.com/tokio-rs/bytes/pull/689 * If `at == self.len()`, we already know `at <= self.len()`. * If `at == 0`, we already know `at <= self.len()`.
This commit is contained in:
+7
-7
@@ -385,13 +385,6 @@ impl Bytes {
|
|||||||
/// Panics if `at > len`.
|
/// Panics if `at > len`.
|
||||||
#[must_use = "consider Bytes::truncate if you don't need the other half"]
|
#[must_use = "consider Bytes::truncate if you don't need the other half"]
|
||||||
pub fn split_off(&mut self, at: usize) -> Self {
|
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() {
|
if at == self.len() {
|
||||||
return Bytes::new();
|
return Bytes::new();
|
||||||
}
|
}
|
||||||
@@ -400,6 +393,13 @@ impl Bytes {
|
|||||||
return mem::replace(self, Bytes::new());
|
return mem::replace(self, Bytes::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
at <= self.len(),
|
||||||
|
"split_off out of bounds: {:?} <= {:?}",
|
||||||
|
at,
|
||||||
|
self.len(),
|
||||||
|
);
|
||||||
|
|
||||||
let mut ret = self.clone();
|
let mut ret = self.clone();
|
||||||
|
|
||||||
self.len = at;
|
self.len = at;
|
||||||
|
|||||||
Reference in New Issue
Block a user