@@ -27,8 +27,8 @@ pub struct Drain<
27
27
drain_len : usize ,
28
28
// index into the logical array, not the physical one (always lies in [0..deque.len))
29
29
idx : usize ,
30
- // number of elements after the drain range
31
- tail_len : usize ,
30
+ // number of elements remaining after dropping the drain
31
+ new_len : usize ,
32
32
remaining : usize ,
33
33
// Needed to make Drain covariant over T
34
34
_marker : PhantomData < & ' a T > ,
@@ -41,12 +41,12 @@ impl<'a, T, A: Allocator> Drain<'a, T, A> {
41
41
drain_len : usize ,
42
42
) -> Self {
43
43
let orig_len = mem:: replace ( & mut deque. len , drain_start) ;
44
- let tail_len = orig_len - drain_start - drain_len;
44
+ let new_len = orig_len - drain_len;
45
45
Drain {
46
46
deque : NonNull :: from ( deque) ,
47
47
drain_len,
48
48
idx : drain_start,
49
- tail_len ,
49
+ new_len ,
50
50
remaining : drain_len,
51
51
_marker : PhantomData ,
52
52
}
@@ -79,7 +79,7 @@ impl<T: fmt::Debug, A: Allocator> fmt::Debug for Drain<'_, T, A> {
79
79
f. debug_tuple ( "Drain" )
80
80
. field ( & self . drain_len )
81
81
. field ( & self . idx )
82
- . field ( & self . tail_len )
82
+ . field ( & self . new_len )
83
83
. field ( & self . remaining )
84
84
. finish ( )
85
85
}
@@ -111,18 +111,16 @@ impl<T, A: Allocator> Drop for Drain<'_, T, A> {
111
111
112
112
let drain_start = source_deque. len ( ) ;
113
113
let drain_len = self . 0 . drain_len ;
114
- let drain_end = drain_start + drain_len;
115
-
116
- let orig_len = self . 0 . tail_len + drain_end;
114
+ let new_len = self . 0 . new_len ;
117
115
118
116
if T :: IS_ZST {
119
117
// no need to copy around any memory if T is a ZST
120
- source_deque. len = orig_len - drain_len ;
118
+ source_deque. len = new_len ;
121
119
return ;
122
120
}
123
121
124
122
let head_len = drain_start;
125
- let tail_len = self . 0 . tail_len ;
123
+ let tail_len = new_len - head_len ;
126
124
127
125
match ( head_len, tail_len) {
128
126
( 0 , 0 ) => {
@@ -131,10 +129,10 @@ impl<T, A: Allocator> Drop for Drain<'_, T, A> {
131
129
}
132
130
( 0 , _) => {
133
131
source_deque. head = source_deque. to_physical_idx ( drain_len) ;
134
- source_deque. len = orig_len - drain_len ;
132
+ source_deque. len = new_len ;
135
133
}
136
134
( _, 0 ) => {
137
- source_deque. len = orig_len - drain_len ;
135
+ source_deque. len = new_len ;
138
136
}
139
137
_ => unsafe {
140
138
if head_len <= tail_len {
@@ -144,14 +142,14 @@ impl<T, A: Allocator> Drop for Drain<'_, T, A> {
144
142
head_len,
145
143
) ;
146
144
source_deque. head = source_deque. to_physical_idx ( drain_len) ;
147
- source_deque. len = orig_len - drain_len ;
145
+ source_deque. len = new_len ;
148
146
} else {
149
147
source_deque. wrap_copy (
150
148
source_deque. to_physical_idx ( head_len + drain_len) ,
151
149
source_deque. to_physical_idx ( head_len) ,
152
150
tail_len,
153
151
) ;
154
- source_deque. len = orig_len - drain_len ;
152
+ source_deque. len = new_len ;
155
153
}
156
154
} ,
157
155
}
0 commit comments