@@ -507,39 +507,34 @@ public abstract static class ListInsertNode extends PythonBuiltinNode {
507
507
@ Specialization (guards = "isIntStorage(list)" )
508
508
public PNone insertIntInt (PList list , int index , int value ) {
509
509
IntSequenceStorage target = (IntSequenceStorage ) list .getSequenceStorage ();
510
- index = normalizeIndex (index , list .len ());
511
- target .insertIntItem (index , value );
510
+ target .insertIntItem (normalizeIndex (index , list .len ()), value );
512
511
return PNone .NONE ;
513
512
}
514
513
515
514
@ Specialization (guards = "isLongStorage(list)" )
516
515
public PNone insertLongLong (PList list , int index , int value ) {
517
516
LongSequenceStorage target = (LongSequenceStorage ) list .getSequenceStorage ();
518
- index = normalizeIndex (index , list .len ());
519
- target .insertLongItem (index , value );
517
+ target .insertLongItem (normalizeIndex (index , list .len ()), value );
520
518
return PNone .NONE ;
521
519
}
522
520
523
521
@ Specialization (guards = "isLongStorage(list)" )
524
522
public PNone insertLongLong (PList list , int index , long value ) {
525
523
LongSequenceStorage target = (LongSequenceStorage ) list .getSequenceStorage ();
526
- index = normalizeIndex (index , list .len ());
527
- target .insertLongItem (index , value );
524
+ target .insertLongItem (normalizeIndex (index , list .len ()), value );
528
525
return PNone .NONE ;
529
526
}
530
527
531
528
@ Specialization (guards = "isDoubleStorage(list)" )
532
529
public PNone insertDoubleDouble (PList list , int index , double value ) {
533
530
DoubleSequenceStorage target = (DoubleSequenceStorage ) list .getSequenceStorage ();
534
- index = normalizeIndex (index , list .len ());
535
- target .insertDoubleItem (index , value );
531
+ target .insertDoubleItem (normalizeIndex (index , list .len ()), value );
536
532
return PNone .NONE ;
537
533
}
538
534
539
535
@ Specialization (guards = "isNotSpecialCase(list, value)" )
540
536
public PNone insert (PList list , int index , Object value ) {
541
- index = normalizeIndex (index , list .len ());
542
- list .insert (index , value );
537
+ list .insert (normalizeIndex (index , list .len ()), value );
543
538
return PNone .NONE ;
544
539
}
545
540
@@ -551,7 +546,6 @@ public PNone insert(PList list, PInt index, Object value) {
551
546
}
552
547
553
548
@ Specialization (guards = {"!isIntegerOrPInt(i)" })
554
- @ SuppressWarnings ("unused" )
555
549
public PNone insert (PList list , Object i , Object value ,
556
550
@ Cached ("create(__INDEX__)" ) LookupAndCallUnaryNode indexNode ,
557
551
@ Cached ("createListInsertNode()" ) ListInsertNode insertNode ) {
@@ -562,17 +556,18 @@ public PNone insert(PList list, Object i, Object value,
562
556
return insertNode .execute (list , indexValue , value );
563
557
}
564
558
565
- private int normalizeIndex (int index , int len ) {
566
- if (index < 0 ) {
567
- index += len ;
568
- if (index < 0 ) {
569
- index = 0 ;
559
+ private static int normalizeIndex (int index , int len ) {
560
+ int idx = index ;
561
+ if (idx < 0 ) {
562
+ idx += len ;
563
+ if (idx < 0 ) {
564
+ idx = 0 ;
570
565
}
571
566
}
572
- if (index > len ) {
573
- index = len ;
567
+ if (idx > len ) {
568
+ idx = len ;
574
569
}
575
- return index ;
570
+ return idx ;
576
571
}
577
572
578
573
protected boolean isNotSpecialCase (PList list , Object value ) {
0 commit comments