@@ -236,6 +236,8 @@ impl<T, const N: usize> Deque<T, N> {
236236 } ;
237237 }
238238
239+ let buffer_ptr: * mut T = self . buffer . as_mut_ptr ( ) . cast ( ) ;
240+
239241 let len = self . len ( ) ;
240242
241243 let free = N - len;
@@ -251,17 +253,9 @@ impl<T, const N: usize> Deque<T, N> {
251253 // from: DEFGH....ABC
252254 // to: ABCDEFGH....
253255 unsafe {
254- ptr:: copy (
255- self . buffer . as_ptr ( ) ,
256- self . buffer . as_mut_ptr ( ) . add ( front_len) ,
257- back_len,
258- ) ;
256+ ptr:: copy ( buffer_ptr, buffer_ptr. add ( front_len) , back_len) ;
259257 // ...DEFGH.ABC
260- ptr:: copy_nonoverlapping (
261- self . buffer . as_ptr ( ) . add ( self . front ) ,
262- self . buffer . as_mut_ptr ( ) ,
263- front_len,
264- ) ;
258+ ptr:: copy_nonoverlapping ( buffer_ptr. add ( self . front ) , buffer_ptr, front_len) ;
265259 // ABCDEFGH....
266260 }
267261
@@ -276,14 +270,14 @@ impl<T, const N: usize> Deque<T, N> {
276270 // to: ...ABCDEFGH.
277271 unsafe {
278272 ptr:: copy (
279- self . buffer . as_ptr ( ) . add ( self . front ) ,
280- self . buffer . as_mut_ptr ( ) . add ( self . back ) ,
273+ buffer_ptr . add ( self . front ) ,
274+ buffer_ptr . add ( self . back ) ,
281275 front_len,
282276 ) ;
283277 // FGHABCDE....
284278 ptr:: copy_nonoverlapping (
285- self . buffer . as_ptr ( ) ,
286- self . buffer . as_mut_ptr ( ) . add ( self . back + front_len) ,
279+ buffer_ptr ,
280+ buffer_ptr . add ( self . back + front_len) ,
287281 back_len,
288282 ) ;
289283 // ...ABCDEFGH.
@@ -321,19 +315,12 @@ impl<T, const N: usize> Deque<T, N> {
321315 // because we only move the tail forward as much as there's free space
322316 // behind it, we don't overwrite any elements of the head slice, and
323317 // the slices end up right next to each other.
324- ptr:: copy (
325- self . buffer . as_ptr ( ) ,
326- self . buffer . as_mut_ptr ( ) . add ( free) ,
327- back_len,
328- ) ;
318+ ptr:: copy ( buffer_ptr, buffer_ptr. add ( free) , back_len) ;
329319 }
330320
331321 // We just copied the tail right next to the head slice,
332322 // so all of the elements in the range are initialized
333- let slice: & mut [ T ] = slice:: from_raw_parts_mut (
334- self . buffer . as_mut_ptr ( ) . add ( free) . cast ( ) ,
335- N - free,
336- ) ;
323+ let slice: & mut [ T ] = slice:: from_raw_parts_mut ( buffer_ptr. add ( free) , N - free) ;
337324
338325 // because the deque wasn't contiguous, we know that `tail_len < self.len == slice.len()`,
339326 // so this will never panic.
@@ -356,16 +343,15 @@ impl<T, const N: usize> Deque<T, N> {
356343 if free != 0 {
357344 // copy the head slice to lie right behind the tail slice.
358345 ptr:: copy (
359- self . buffer . as_ptr ( ) . add ( self . front ) ,
360- self . buffer . as_mut_ptr ( ) . add ( back_len) ,
346+ buffer_ptr . add ( self . front ) ,
347+ buffer_ptr . add ( back_len) ,
361348 front_len,
362349 ) ;
363350 }
364351
365352 // because we copied the head slice so that both slices lie right
366353 // next to each other, all the elements in the range are initialized.
367- let slice: & mut [ T ] =
368- slice:: from_raw_parts_mut ( self . buffer . as_mut_ptr ( ) . cast ( ) , len) ;
354+ let slice: & mut [ T ] = slice:: from_raw_parts_mut ( buffer_ptr, len) ;
369355
370356 // because the deque wasn't contiguous, we know that `head_len < self.len == slice.len()`
371357 // so this will never panic.
@@ -379,7 +365,7 @@ impl<T, const N: usize> Deque<T, N> {
379365 }
380366 }
381367
382- unsafe { slice:: from_raw_parts_mut ( self . buffer . as_mut_ptr ( ) . add ( self . front ) . cast ( ) , len) }
368+ unsafe { slice:: from_raw_parts_mut ( buffer_ptr . add ( self . front ) , len) }
383369 }
384370
385371 /// Provides a reference to the front element, or None if the `Deque` is empty.
0 commit comments