@@ -236,6 +236,8 @@ impl<T, const N: usize> Deque<T, N> {
236
236
} ;
237
237
}
238
238
239
+ let buffer_ptr: * mut T = self . buffer . as_mut_ptr ( ) . cast ( ) ;
240
+
239
241
let len = self . len ( ) ;
240
242
241
243
let free = N - len;
@@ -251,17 +253,9 @@ impl<T, const N: usize> Deque<T, N> {
251
253
// from: DEFGH....ABC
252
254
// to: ABCDEFGH....
253
255
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) ;
259
257
// ...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) ;
265
259
// ABCDEFGH....
266
260
}
267
261
@@ -276,14 +270,14 @@ impl<T, const N: usize> Deque<T, N> {
276
270
// to: ...ABCDEFGH.
277
271
unsafe {
278
272
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 ) ,
281
275
front_len,
282
276
) ;
283
277
// FGHABCDE....
284
278
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) ,
287
281
back_len,
288
282
) ;
289
283
// ...ABCDEFGH.
@@ -321,19 +315,12 @@ impl<T, const N: usize> Deque<T, N> {
321
315
// because we only move the tail forward as much as there's free space
322
316
// behind it, we don't overwrite any elements of the head slice, and
323
317
// 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) ;
329
319
}
330
320
331
321
// We just copied the tail right next to the head slice,
332
322
// 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) ;
337
324
338
325
// because the deque wasn't contiguous, we know that `tail_len < self.len == slice.len()`,
339
326
// so this will never panic.
@@ -356,16 +343,15 @@ impl<T, const N: usize> Deque<T, N> {
356
343
if free != 0 {
357
344
// copy the head slice to lie right behind the tail slice.
358
345
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) ,
361
348
front_len,
362
349
) ;
363
350
}
364
351
365
352
// because we copied the head slice so that both slices lie right
366
353
// 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) ;
369
355
370
356
// because the deque wasn't contiguous, we know that `head_len < self.len == slice.len()`
371
357
// so this will never panic.
@@ -379,7 +365,7 @@ impl<T, const N: usize> Deque<T, N> {
379
365
}
380
366
}
381
367
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) }
383
369
}
384
370
385
371
/// Provides a reference to the front element, or None if the `Deque` is empty.
0 commit comments