From 91e88a4976cf4d61026a3ed8d7589cb18f8e9d18 Mon Sep 17 00:00:00 2001 From: bluss Date: Sun, 25 Nov 2018 16:33:07 +0100 Subject: [PATCH] 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. --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 75860dd..fb40456 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -890,10 +890,10 @@ impl Extend for ArrayVec { // 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) {