-
- Downloads
Handle corner cases of Bytes::split_{off,to} (#87)
Before this commit `Bytes::split_{off,to}` always created a shallow copy if `self` is arc or vec. However, in certain cases `split_off` or `split_to` is called with `len` or `0` parameter. E. g. if you are reading a frame from buffered stream, it is likely that buffer contains exactly the frame size bytes, so `split_to` will be called with `len` param. Although, `split_off` and `split_to` functions are `O(1)`, shallow copy have downsides: * shallow copy on vector does malloc and atomic cmpxchg * after shallow copy, following operations (e. g. `drop`) on both `bytes` objects require atomics * memory will be probably released to the system later * `try_mut` will fail * [into_vec](https://github.com/carllerche/bytes/issues/86) will copy
Please register or sign in to comment