FEAT: Improved extend performance
This commit is contained in:
+11
-4
@@ -933,6 +933,7 @@ impl<A: Array> Extend<A::Item> for ArrayVec<A> {
|
|||||||
unsafe {
|
unsafe {
|
||||||
let len = self.len();
|
let len = self.len();
|
||||||
let mut ptr = self.as_mut_ptr().offset(len as isize);
|
let mut ptr = self.as_mut_ptr().offset(len as isize);
|
||||||
|
let end_ptr = ptr.offset(take as isize);
|
||||||
// Keep the length in a separate variable, write it back on scope
|
// Keep the length in a separate variable, write it back on scope
|
||||||
// exit. To help the compiler with alias analysis and stuff.
|
// exit. To help the compiler with alias analysis and stuff.
|
||||||
// We update the length to handle panic in the iteration of the
|
// We update the length to handle panic in the iteration of the
|
||||||
@@ -944,10 +945,16 @@ impl<A: Array> Extend<A::Item> for ArrayVec<A> {
|
|||||||
**self_len = Index::from(len);
|
**self_len = Index::from(len);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
for elt in iter.into_iter().take(take) {
|
let mut iter = iter.into_iter();
|
||||||
ptr::write(ptr, elt);
|
loop {
|
||||||
ptr = ptr.offset(1);
|
if ptr == end_ptr { break; }
|
||||||
guard.data += 1;
|
if let Some(elt) = iter.next() {
|
||||||
|
ptr::write(ptr, elt);
|
||||||
|
ptr = ptr.offset(1);
|
||||||
|
guard.data += 1;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user