Merge pull request #111 from bluss/miri-complaints

Fix just a few stacked borrow issues, and improve extend performance
This commit is contained in:
bluss
2018-11-25 17:17:43 +01:00
committed by GitHub
2 changed files with 9 additions and 8 deletions
+2 -1
View File
@@ -5,6 +5,7 @@ extern crate arrayvec;
use arrayvec::ArrayVec;
use bencher::Bencher;
use bencher::black_box;
fn extend_with_constant(b: &mut Bencher) {
let mut v = ArrayVec::<[u8; 512]>::new();
@@ -33,7 +34,7 @@ fn extend_with_slice(b: &mut Bencher) {
let data = [1; 512];
b.iter(|| {
v.clear();
v.extend(data.iter().cloned());
v.extend(black_box(data.iter()).cloned());
v[0]
});
b.bytes = v.capacity() as u64;
+7 -7
View File
@@ -461,11 +461,11 @@ impl<A: Array> ArrayVec<A> {
/// array.truncate(4);
/// assert_eq!(&array[..], &[1, 2, 3]);
/// ```
pub fn truncate(&mut self, len: usize) {
pub fn truncate(&mut self, new_len: usize) {
unsafe {
if len < self.len() {
let tail: *mut [_] = &mut self[len..];
self.set_len(len);
if new_len < self.len() {
let tail: *mut [_] = &mut self[new_len..];
self.len = Index::from(new_len);
ptr::drop_in_place(tail);
}
}
@@ -890,10 +890,10 @@ impl<A: Array> Extend<A::Item> for ArrayVec<A> {
// We update the length to handle panic in the iteration of the
// user's iterator, without dropping any elements on the floor.
let mut guard = ScopeExitGuard {
value: self,
value: &mut self.len,
data: len,
f: |&len, self_| {
self_.set_len(len)
f: move |&len, self_len| {
**self_len = Index::from(len);
}
};
for elt in iter.into_iter().take(take) {