Skip to content

Commit

Permalink
Fix TinyVec::resize across inline/heap boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo157 committed Jan 13, 2020
1 parent d0bdff5 commit 001b33e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/tiny_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,12 @@ impl<A: Arrayish> TinyVec<A> {
A::Item: Clone,
{
match self {
TinyVec::Inline(a) => a.resize(new_len, new_val),
TinyVec::Inline(a) => if new_len > A::CAPACITY {
self.move_to_the_heap();
self.resize(new_len, new_val);
} else {
a.resize(new_len, new_val);
},
TinyVec::Heap(v) => v.resize(new_len, new_val),
}
}
Expand Down
8 changes: 7 additions & 1 deletion tests/tinyvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use tinyvec::*;
use std::iter::FromIterator;

#[test]
fn TinyVec_drain() {
let mut tv: TinyVec<[i32; 10]> = Default::default();
tv.push(1);
Expand Down Expand Up @@ -31,3 +30,10 @@ fn TinyVec_drain() {
assert_eq!(Vec::from_iter(tv.clone().drain(1..=1)), vec![2]);
assert_eq!(Vec::from_iter(tv.clone().drain(1..=2)), vec![2, 3]);
}

#[test]
fn TinyVec_resize() {
let mut tv: TinyVec<[i32; 10]> = Default::default();
tv.resize(20, 5);
assert_eq!(&tv[..], &[5; 20]);
}

0 comments on commit 001b33e

Please sign in to comment.