mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-15 00:00:18 +02:00
Optimize Bytes::slice(n, n) (#123)
Return empty `Bytes` object Bench for `slice_empty` difference is ``` 55 ns/iter (+/- 1) # before this patch 17 ns/iter (+/- 5) # with this patch ``` Bench for `slice_not_empty` is ``` 25,058 ns/iter (+/- 1,099) # before this patch 25,072 ns/iter (+/- 1,593) # with this patch ```
This commit is contained in:
committed by
Carl Lerche
parent
70ee87ea29
commit
3f5890be70
@@ -464,6 +464,11 @@ impl Bytes {
|
||||
/// Requires that `begin <= end` and `end <= self.len()`, otherwise slicing
|
||||
/// will panic.
|
||||
pub fn slice(&self, begin: usize, end: usize) -> Bytes {
|
||||
if begin == end {
|
||||
assert!(begin <= self.len());
|
||||
return Bytes::new();
|
||||
}
|
||||
|
||||
let mut ret = self.clone();
|
||||
|
||||
unsafe {
|
||||
|
||||
Reference in New Issue
Block a user