File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -819,7 +819,7 @@ impl BytesMut {
819
819
}
820
820
821
821
fn try_unsplit ( & mut self , other : BytesMut ) -> Result < ( ) , BytesMut > {
822
- if other. is_empty ( ) {
822
+ if other. capacity ( ) == 0 {
823
823
return Ok ( ( ) ) ;
824
824
}
825
825
Original file line number Diff line number Diff line change @@ -784,6 +784,31 @@ fn bytes_mut_unsplit_empty_self() {
784
784
assert_eq ! ( b"aaabbbcccddd" , & buf[ ..] ) ;
785
785
}
786
786
787
+ #[ test]
788
+ fn bytes_mut_unsplit_other_keeps_capacity ( ) {
789
+ let mut buf = BytesMut :: with_capacity ( 64 ) ;
790
+ buf. extend_from_slice ( b"aabb" ) ;
791
+
792
+ // non empty other created "from" buf
793
+ let mut other = buf. split_off ( buf. len ( ) ) ;
794
+ other. extend_from_slice ( b"ccddee" ) ;
795
+ buf. unsplit ( other) ;
796
+
797
+ assert_eq ! ( buf. capacity( ) , 64 ) ;
798
+ }
799
+
800
+ #[ test]
801
+ fn bytes_mut_unsplit_empty_other_keeps_capacity ( ) {
802
+ let mut buf = BytesMut :: with_capacity ( 64 ) ;
803
+ buf. extend_from_slice ( b"aabbccddee" ) ;
804
+
805
+ // empty other created "from" buf
806
+ let other = buf. split_off ( buf. len ( ) ) ;
807
+ buf. unsplit ( other) ;
808
+
809
+ assert_eq ! ( buf. capacity( ) , 64 ) ;
810
+ }
811
+
787
812
#[ test]
788
813
fn bytes_mut_unsplit_arc_different ( ) {
789
814
let mut buf = BytesMut :: with_capacity ( 64 ) ;
You can’t perform that action at this time.
0 commit comments