Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bytes::split_to - check fast path first #689

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Bytes::split_to - check fast path first
If `at == self.len()` then we already know `at <= self.len()`. If
`at == 0`, it can't be greater than `self.len()`.
  • Loading branch information
braddunbar committed Apr 10, 2024
commit 307de6afe471397c41bf24b4f09a281f9ddc00aa
14 changes: 7 additions & 7 deletions src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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) };
Expand Down