FEAT: Simplify stack guard in extend
This simplification -- borrowing self.len instead of self, leads to an improvement in the extend_from_slice benchmark. It's also guided by the discussion of stacked borrows; the old code would be invalid, because the whole self is borrowed while ptr is derived from self.
This commit is contained in:
+3
-3
@@ -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