mirror of
https://github.com/openharmony/third_party_rust_rust-smallvec.git
synced 2026-07-21 01:55:25 -04:00
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 -->
This commit is contained in:
@@ -665,6 +665,8 @@ impl<A: Array> SmallVec<A> {
|
||||
if unspilled {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
deallocate(ptr, cap);
|
||||
}
|
||||
@@ -2341,4 +2343,18 @@ mod tests {
|
||||
v.extend(it);
|
||||
assert_eq!(v[..], ['a']);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn grow_spilled_same_size() {
|
||||
let mut v: SmallVec<[u8; 2]> = SmallVec::new();
|
||||
v.push(0);
|
||||
v.push(1);
|
||||
v.push(2);
|
||||
assert!(v.spilled());
|
||||
assert_eq!(v.capacity(), 4);
|
||||
// grow with the same capacity
|
||||
v.grow(4);
|
||||
assert_eq!(v.capacity(), 4);
|
||||
assert_eq!(v[..], [0, 1, 2]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user