Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion benches/extend.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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();
Expand DownExpand Up@@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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);
}
}
Expand DownExpand Up@@ -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) {
Expand Down