Skip to content

Commit c20cfa8

Browse files
author
bors-servo
authored
Auto merge of #151 - ehuss:grow-same-size, r=jdm
Fix using `grow` to the same size. Using `grow` on a spilled SmallVec to the current capacity would free the backing storage when it shouldn't. Fixes #148 <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-smallvec/151) <!-- Reviewable:end -->
2 parents 88b62b6 + 4ba0d0f commit c20cfa8

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)