Skip to content

Commit

Permalink
Auto merge of #151 - ehuss:grow-same-size, r=jdm
Browse files Browse the repository at this point in the history
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 -->
  • Loading branch information
bors-servo committed Jun 8, 2019
2 parents 88b62b6 + 4ba0d0f commit c20cfa8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib.rs
Expand Up @@ -665,6 +665,8 @@ impl<A: Array> SmallVec<A> {
if unspilled {
return;
}
} else {
return;
}
deallocate(ptr, cap);
}
Expand Down Expand Up @@ -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]);
}
}

0 comments on commit c20cfa8

Please sign in to comment.