aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Brad Dunbar <dunbarb2@gmail.com> 2024-04-10 04:09:09 -0400
committerGravatar GitHub <noreply@github.com> 2024-04-10 10:09:09 +0200
commit4eb62b912a199bef711e7e12243d972f4f0cdca8 (patch)
tree79eaa7113bfd1434281d0f55deaa2b54d192ed1e
parente4af48633cec419e8274571d353fe166d5e23a3e (diff)
downloadbytes-4eb62b912a199bef711e7e12243d972f4f0cdca8.tar.gz
bytes-4eb62b912a199bef711e7e12243d972f4f0cdca8.tar.zst
bytes-4eb62b912a199bef711e7e12243d972f4f0cdca8.zip
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()`.
-rw-r--r--src/bytes.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/bytes.rs b/src/bytes.rs
index 4a0a94f..63c06ce 100644
--- a/src/bytes.rs
+++ b/src/bytes.rs
@@ -434,13 +434,6 @@ impl Bytes {
/// Panics if `at > len`.
#[must_use = "consider Bytes::advance if you don't need the other half"]
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() {
return mem::replace(self, Bytes::new());
}
@@ -449,6 +442,13 @@ impl Bytes {
return Bytes::new();
}
+ assert!(
+ at <= self.len(),
+ "split_to out of bounds: {:?} <= {:?}",
+ at,
+ self.len(),
+ );
+
let mut ret = self.clone();
unsafe { self.inc_start(at) };