Skip to content

Commit b28c6b3

Browse files
committed
Fix using grow to the same size.
1 parent f96322b commit b28c6b3

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
}
@@ -2329,4 +2331,18 @@ mod tests {
23292331
v.push(4);
23302332
assert_eq!(v[..], [4]);
23312333
}
2334+
2335+
#[test]
2336+
fn grow_spilled_same_size() {
2337+
let mut v: SmallVec<[u8; 2]> = SmallVec::new();
2338+
v.push(0);
2339+
v.push(1);
2340+
v.push(2);
2341+
assert!(v.spilled());
2342+
assert_eq!(v.capacity(), 4);
2343+
// grow with the same capacity
2344+
v.grow(4);
2345+
assert_eq!(v.capacity(), 4);
2346+
assert_eq!(v[..], [0, 1, 2]);
2347+
}
23322348
}

0 commit comments

Comments
 (0)