Merge pull request #111 from bluss/miri-complaints
Fix just a few stacked borrow issues, and improve extend performance
This commit is contained in:
+2
-1
@@ -5,6 +5,7 @@ extern crate arrayvec;
|
|||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
|
|
||||||
use bencher::Bencher;
|
use bencher::Bencher;
|
||||||
|
use bencher::black_box;
|
||||||
|
|
||||||
fn extend_with_constant(b: &mut Bencher) {
|
fn extend_with_constant(b: &mut Bencher) {
|
||||||
let mut v = ArrayVec::<[u8; 512]>::new();
|
let mut v = ArrayVec::<[u8; 512]>::new();
|
||||||
@@ -33,7 +34,7 @@ fn extend_with_slice(b: &mut Bencher) {
|
|||||||
let data = [1; 512];
|
let data = [1; 512];
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
v.clear();
|
v.clear();
|
||||||
v.extend(data.iter().cloned());
|
v.extend(black_box(data.iter()).cloned());
|
||||||
v[0]
|
v[0]
|
||||||
});
|
});
|
||||||
b.bytes = v.capacity() as u64;
|
b.bytes = v.capacity() as u64;
|
||||||
|
|||||||
+7
-7
@@ -461,11 +461,11 @@ impl<A: Array> ArrayVec<A> {
|
|||||||
/// array.truncate(4);
|
/// array.truncate(4);
|
||||||
/// assert_eq!(&array[..], &[1, 2, 3]);
|
/// assert_eq!(&array[..], &[1, 2, 3]);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn truncate(&mut self, len: usize) {
|
pub fn truncate(&mut self, new_len: usize) {
|
||||||
unsafe {
|
unsafe {
|
||||||
if len < self.len() {
|
if new_len < self.len() {
|
||||||
let tail: *mut [_] = &mut self[len..];
|
let tail: *mut [_] = &mut self[new_len..];
|
||||||
self.set_len(len);
|
self.len = Index::from(new_len);
|
||||||
ptr::drop_in_place(tail);
|
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
|
// We update the length to handle panic in the iteration of the
|
||||||
// user's iterator, without dropping any elements on the floor.
|
// user's iterator, without dropping any elements on the floor.
|
||||||
let mut guard = ScopeExitGuard {
|
let mut guard = ScopeExitGuard {
|
||||||
value: self,
|
value: &mut self.len,
|
||||||
data: len,
|
data: len,
|
||||||
f: |&len, self_| {
|
f: move |&len, self_len| {
|
||||||
self_.set_len(len)
|
**self_len = Index::from(len);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
for elt in iter.into_iter().take(take) {
|
for elt in iter.into_iter().take(take) {
|
||||||
|
|||||||
Reference in New Issue
Block a user