@@ -247,7 +247,7 @@ where
247
247
Pool : ops:: Index < Index , Output = Element > ,
248
248
MapLink : Fn ( & Element ) -> & LinkCell ,
249
249
LinkCell : CellLike < CellKey , Target = Option < Link < Index > > > ,
250
- Index : PartialEq + Clone ,
250
+ Index : PartialEq + Copy ,
251
251
{
252
252
pub fn new ( head : HeadCell , pool : & ' a Pool , map_link : MapLink , cell_key : CellKey ) -> Self {
253
253
ListAccessorCell {
@@ -286,7 +286,7 @@ where
286
286
Pool : ops:: Index < Index , Output = Element > ,
287
287
MapLink : Fn ( & Element ) -> & LinkCell ,
288
288
LinkCell : CellLike < CellKey , Target = Option < Link < Index > > > ,
289
- Index : PartialEq + Clone ,
289
+ Index : PartialEq + Copy ,
290
290
InconsistencyHandler : HandleInconsistency ,
291
291
{
292
292
pub fn head_cell ( & self ) -> & HeadCell {
@@ -357,7 +357,7 @@ where
357
357
item : Index ,
358
358
at : Option < Index > ,
359
359
) -> Result < ( ) , InsertError < InconsistencyHandler :: Output > > {
360
- if ( self . map_link ) ( & self . pool [ item. clone ( ) ] )
360
+ if ( self . map_link ) ( & self . pool [ item] )
361
361
. get ( & self . cell_key )
362
362
. is_some ( )
363
363
{
@@ -377,43 +377,42 @@ where
377
377
( first, false )
378
378
} ;
379
379
380
- let prev = ( self . map_link ) ( & self . pool [ next. clone ( ) ] )
380
+ let prev = ( self . map_link ) ( & self . pool [ next] )
381
381
. get ( & self . cell_key )
382
382
. ok_or_else ( on_inconsistency) ?
383
383
. prev ;
384
384
385
385
// prev.next = item
386
- ( self . map_link ) ( & self . pool [ prev. clone ( ) ] ) . modify ( & mut self . cell_key , |l| match l {
386
+ ( self . map_link ) ( & self . pool [ prev] ) . modify ( & mut self . cell_key , |l| match l {
387
387
// Don't replace this part with the following code:
388
388
//
389
- // l.as_mut().ok_or_else(on_inconsistency)?.next = item.clone() ;
389
+ // l.as_mut().ok_or_else(on_inconsistency)?.next = item;
390
390
//
391
391
// When `HandleInconsistencyUnchecked` is in use, the above code
392
392
// can be "optimized" to the following code, which is very
393
393
// inefficient:
394
394
//
395
- // l.as_mut().unwrap_or(0).next = item.clone() ;
395
+ // l.as_mut().unwrap_or(0).next = item;
396
396
//
397
397
Some ( l) => {
398
- l. next = item. clone ( ) ;
398
+ l. next = item;
399
399
Ok :: < ( ) , InconsistencyHandler :: Output > ( ( ) )
400
400
}
401
401
None => Err ( on_inconsistency ( ) ) ,
402
402
} ) ?;
403
403
404
404
// next.prev = item
405
- ( self . map_link ) ( & self . pool [ next. clone ( ) ] ) . modify ( & mut self . cell_key , |l| match l {
405
+ ( self . map_link ) ( & self . pool [ next] ) . modify ( & mut self . cell_key , |l| match l {
406
406
Some ( l) => {
407
- l. prev = item. clone ( ) ;
407
+ l. prev = item;
408
408
Ok :: < ( ) , InconsistencyHandler :: Output > ( ( ) )
409
409
}
410
410
None => Err ( on_inconsistency ( ) ) ,
411
411
} ) ?;
412
412
413
413
// item.prev = prev
414
414
// item.next = next
415
- ( self . map_link ) ( & self . pool [ item. clone ( ) ] )
416
- . set ( & mut self . cell_key , Some ( Link { prev, next } ) ) ;
415
+ ( self . map_link ) ( & self . pool [ item] ) . set ( & mut self . cell_key , Some ( Link { prev, next } ) ) ;
417
416
418
417
if update_first {
419
418
head. first = Some ( item) ;
@@ -422,12 +421,12 @@ where
422
421
} else {
423
422
debug_assert ! ( at. is_none( ) ) ;
424
423
425
- let link = ( self . map_link ) ( & self . pool [ item. clone ( ) ] ) ;
424
+ let link = ( self . map_link ) ( & self . pool [ item] ) ;
426
425
link. set (
427
426
& mut self . cell_key ,
428
427
Some ( Link {
429
- prev : item. clone ( ) ,
430
- next : item. clone ( ) ,
428
+ prev : item,
429
+ next : item,
431
430
} ) ,
432
431
) ;
433
432
@@ -461,7 +460,7 @@ where
461
460
& mut self ,
462
461
item : Index ,
463
462
) -> Result < Index , ItemError < InconsistencyHandler :: Output > > {
464
- if ( self . map_link ) ( & self . pool [ item. clone ( ) ] )
463
+ if ( self . map_link ) ( & self . pool [ item] )
465
464
. get ( & self . cell_key )
466
465
. is_none ( )
467
466
{
@@ -479,9 +478,9 @@ where
479
478
} }
480
479
481
480
let link: Link < Index > = {
482
- let link_ref = ( self . map_link ) ( & self . pool [ item. clone ( ) ] ) ;
481
+ let link_ref = ( self . map_link ) ( & self . pool [ item] ) ;
483
482
let mut head = self . head ( ) ;
484
- if head. first . as_ref ( ) == Some ( & item) {
483
+ if head. first == Some ( item) {
485
484
let next = link_ref
486
485
. get ( & self . cell_key )
487
486
. ok_or_else ( on_inconsistency ! ( ) ) ?
@@ -509,26 +508,26 @@ where
509
508
let on_inconsistency = on_inconsistency ! ( ) ;
510
509
511
510
// link.prev.next = link.next
512
- ( self . map_link ) ( & self . pool [ link. prev . clone ( ) ] ) . modify ( & mut self . cell_key , |l| match l {
511
+ ( self . map_link ) ( & self . pool [ link. prev ] ) . modify ( & mut self . cell_key , |l| match l {
513
512
Some ( l) => {
514
- l. next = link. next . clone ( ) ;
513
+ l. next = link. next ;
515
514
Ok :: < ( ) , InconsistencyHandler :: Output > ( ( ) )
516
515
}
517
516
None => Err ( on_inconsistency ( ) ) ,
518
517
} ) ?;
519
518
520
519
// link.next.prev = link.prev
521
- ( self . map_link ) ( & self . pool [ link. next . clone ( ) ] ) . modify ( & mut self . cell_key , |l| match l {
520
+ ( self . map_link ) ( & self . pool [ link. next ] ) . modify ( & mut self . cell_key , |l| match l {
522
521
Some ( l) => {
523
- l. prev = link. prev . clone ( ) ;
522
+ l. prev = link. prev ;
524
523
Ok :: < ( ) , InconsistencyHandler :: Output > ( ( ) )
525
524
}
526
525
None => Err ( on_inconsistency ( ) ) ,
527
526
} ) ?;
528
527
529
528
// item.prev = null
530
529
// item.next = null
531
- ( self . map_link ) ( & self . pool [ item. clone ( ) ] ) . set ( & mut self . cell_key , None ) ;
530
+ ( self . map_link ) ( & self . pool [ item] ) . set ( & mut self . cell_key , None ) ;
532
531
533
532
Ok ( item)
534
533
}
@@ -564,7 +563,7 @@ where
564
563
. get ( & self . cell_key )
565
564
. ok_or ( ItemError :: NotLinked ) ?
566
565
. next ;
567
- Ok ( if Some ( & next) == self . head ( ) . first . as_ref ( ) {
566
+ Ok ( if Some ( next) == self . head ( ) . first {
568
567
None
569
568
} else {
570
569
Some ( next)
@@ -574,7 +573,7 @@ where
574
573
/// Get the previous element of the specified element.
575
574
#[ inline]
576
575
pub fn prev ( & self , i : Index ) -> Result < Option < Index > , ItemError < InconsistencyHandler :: Output > > {
577
- Ok ( if Some ( & i) == self . head ( ) . first . as_ref ( ) {
576
+ Ok ( if Some ( i) == self . head ( ) . first {
578
577
None
579
578
} else {
580
579
Some (
@@ -623,18 +622,18 @@ where
623
622
MapLink : ' a + Fn ( & Element ) -> & LinkCell ,
624
623
Element : ' a + ' b ,
625
624
LinkCell : CellLike < CellKey , Target = Option < Link < Index > > > ,
626
- Index : PartialEq + Clone ,
625
+ Index : PartialEq + Copy ,
627
626
InconsistencyHandler : HandleInconsistency ,
628
627
{
629
628
type Item = Result < ( Index , & ' a Element ) , InconsistencyHandler :: Output > ;
630
629
631
630
fn next ( & mut self ) -> Option < Self :: Item > {
632
631
if let Some ( next) = self . next . take ( ) {
633
- self . next = match self . accessor . next ( next. clone ( ) ) {
632
+ self . next = match self . accessor . next ( next) {
634
633
Ok ( x) => x,
635
634
Err ( _) => return Some ( Err ( self . accessor . inconsistency_handler . on_inconsistency ( ) ) ) ,
636
635
} ;
637
- Some ( Ok ( ( next. clone ( ) , & self . accessor . pool [ next] ) ) )
636
+ Some ( Ok ( ( next, & self . accessor . pool [ next] ) ) )
638
637
} else {
639
638
None
640
639
}
0 commit comments