File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -1283,9 +1283,7 @@ impl Extend<u8> for BytesMut {
1283
1283
1284
1284
// TODO: optimize
1285
1285
// 1. If self.kind() == KIND_VEC, use Vec::extend
1286
- // 2. Make `reserve` inline-able
1287
1286
for b in iter {
1288
- self . reserve ( 1 ) ;
1289
1287
self . put_u8 ( b) ;
1290
1288
}
1291
1289
}
Original file line number Diff line number Diff line change @@ -598,6 +598,28 @@ fn extend_mut_from_bytes() {
598
598
assert_eq ! ( * bytes, LONG [ ..] ) ;
599
599
}
600
600
601
+ #[ test]
602
+ fn extend_past_lower_limit_of_size_hint ( ) {
603
+ // See https://github.com/tokio-rs/bytes/pull/674#pullrequestreview-1913035700
604
+ struct Iter < I > ( I ) ;
605
+
606
+ impl < I : Iterator < Item = u8 > > Iterator for Iter < I > {
607
+ type Item = u8 ;
608
+
609
+ fn next ( & mut self ) -> Option < Self :: Item > {
610
+ self . 0 . next ( )
611
+ }
612
+
613
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
614
+ ( 5 , None )
615
+ }
616
+ }
617
+
618
+ let mut bytes = BytesMut :: with_capacity ( 5 ) ;
619
+ bytes. extend ( Iter ( std:: iter:: repeat ( 0 ) . take ( 10 ) ) ) ;
620
+ assert_eq ! ( bytes. len( ) , 10 ) ;
621
+ }
622
+
601
623
#[ test]
602
624
fn extend_mut_without_size_hint ( ) {
603
625
let mut bytes = BytesMut :: with_capacity ( 0 ) ;
You can’t perform that action at this time.
0 commit comments