Skip to content

Commit 044811e

Browse files
committed
Avoid holding a refcount to an allocation for empty slices.
1 parent 280a0c4 commit 044811e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/bytes.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,10 @@ impl Bytes {
400400
len,
401401
);
402402

403+
if end == begin {
404+
return Bytes::new_empty_with_ptr(self.ptr.wrapping_add(begin));
405+
}
406+
403407
let mut ret = self.clone();
404408

405409
ret.len = end - begin;

0 commit comments

Comments
 (0)