diff options
-rw-r--r-- | src/bytes_mut.rs | 2 | ||||
-rw-r--r-- | tests/test_bytes.rs | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/bytes_mut.rs b/src/bytes_mut.rs index 2af58e3..8e42079 100644 --- a/src/bytes_mut.rs +++ b/src/bytes_mut.rs @@ -819,7 +819,7 @@ impl BytesMut { } fn try_unsplit(&mut self, other: BytesMut) -> Result<(), BytesMut> { - if other.is_empty() { + if other.capacity() == 0 { return Ok(()); } diff --git a/tests/test_bytes.rs b/tests/test_bytes.rs index b9e6ce4..2d22fdd 100644 --- a/tests/test_bytes.rs +++ b/tests/test_bytes.rs @@ -785,6 +785,31 @@ fn bytes_mut_unsplit_empty_self() { } #[test] +fn bytes_mut_unsplit_other_keeps_capacity() { + let mut buf = BytesMut::with_capacity(64); + buf.extend_from_slice(b"aabb"); + + // non empty other created "from" buf + let mut other = buf.split_off(buf.len()); + other.extend_from_slice(b"ccddee"); + buf.unsplit(other); + + assert_eq!(buf.capacity(), 64); +} + +#[test] +fn bytes_mut_unsplit_empty_other_keeps_capacity() { + let mut buf = BytesMut::with_capacity(64); + buf.extend_from_slice(b"aabbccddee"); + + // empty other created "from" buf + let other = buf.split_off(buf.len()); + buf.unsplit(other); + + assert_eq!(buf.capacity(), 64); +} + +#[test] fn bytes_mut_unsplit_arc_different() { let mut buf = BytesMut::with_capacity(64); buf.extend_from_slice(b"aaaabbbbeeee"); |