File tree 2 files changed +13
-2
lines changed
2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -405,7 +405,12 @@ impl<A: Arrayish> TinyVec<A> {
405
405
A :: Item : Clone ,
406
406
{
407
407
match self {
408
- TinyVec :: Inline ( a) => a. resize ( new_len, new_val) ,
408
+ TinyVec :: Inline ( a) => if new_len > A :: CAPACITY {
409
+ self . move_to_the_heap ( ) ;
410
+ self . resize ( new_len, new_val) ;
411
+ } else {
412
+ a. resize ( new_len, new_val) ;
413
+ } ,
409
414
TinyVec :: Heap ( v) => v. resize ( new_len, new_val) ,
410
415
}
411
416
}
Original file line number Diff line number Diff line change 3
3
use tinyvec:: * ;
4
4
use std:: iter:: FromIterator ;
5
5
6
- #[ test]
7
6
fn TinyVec_drain ( ) {
8
7
let mut tv: TinyVec < [ i32 ; 10 ] > = Default :: default ( ) ;
9
8
tv. push ( 1 ) ;
@@ -31,3 +30,10 @@ fn TinyVec_drain() {
31
30
assert_eq ! ( Vec :: from_iter( tv. clone( ) . drain( 1 ..=1 ) ) , vec![ 2 ] ) ;
32
31
assert_eq ! ( Vec :: from_iter( tv. clone( ) . drain( 1 ..=2 ) ) , vec![ 2 , 3 ] ) ;
33
32
}
33
+
34
+ #[ test]
35
+ fn TinyVec_resize ( ) {
36
+ let mut tv: TinyVec < [ i32 ; 10 ] > = Default :: default ( ) ;
37
+ tv. resize ( 20 , 5 ) ;
38
+ assert_eq ! ( & tv[ ..] , & [ 5 ; 20 ] ) ;
39
+ }
You can’t perform that action at this time.
0 commit comments