Skip to content

Commit 4ba0d0f

Browse files
committed
Fix using grow to the same size.
1 parent 88b62b6 commit 4ba0d0f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib.rs

+16
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,8 @@ impl<A: Array> SmallVec<A> {
665665
if unspilled {
666666
return;
667667
}
668+
} else {
669+
return;
668670
}
669671
deallocate(ptr, cap);
670672
}
@@ -2341,4 +2343,18 @@ mod tests {
23412343
v.extend(it);
23422344
assert_eq!(v[..], ['a']);
23432345
}
2346+
2347+
#[test]
2348+
fn grow_spilled_same_size() {
2349+
let mut v: SmallVec<[u8; 2]> = SmallVec::new();
2350+
v.push(0);
2351+
v.push(1);
2352+
v.push(2);
2353+
assert!(v.spilled());
2354+
assert_eq!(v.capacity(), 4);
2355+
// grow with the same capacity
2356+
v.grow(4);
2357+
assert_eq!(v.capacity(), 4);
2358+
assert_eq!(v[..], [0, 1, 2]);
2359+
}
23442360
}

0 commit comments

Comments
 (0)