@@ -547,18 +547,9 @@ public PNone insertLongIndex(PList list, long index, Object value,
547
547
}
548
548
549
549
@ Specialization
550
- @ TruffleBoundary
551
550
public PNone insertPIntIndex (PList list , PInt index , Object value ,
552
551
@ Cached ("createListInsertNode()" ) ListInsertNode insertNode ) {
553
- int where = 0 ;
554
- BigInteger bigIndex = index .getValue ();
555
- if (bigIndex .compareTo (BigInteger .valueOf (Integer .MIN_VALUE )) == -1 ) {
556
- where = 0 ;
557
- } else if (bigIndex .compareTo (BigInteger .valueOf (Integer .MAX_VALUE )) == 1 ) {
558
- where = Integer .MAX_VALUE ;
559
- } else {
560
- where = bigIndex .intValue ();
561
- }
552
+ int where = normalizePIntForIndex (index );
562
553
where = normalizeIndex (where , list .len ());
563
554
return insertNode .execute (list , where , value );
564
555
}
@@ -574,6 +565,20 @@ public PNone insert(PList list, Object i, Object value,
574
565
return insertNode .execute (list , indexValue , value );
575
566
}
576
567
568
+ @ TruffleBoundary
569
+ private static int normalizePIntForIndex (PInt index ) {
570
+ int where = 0 ;
571
+ BigInteger bigIndex = index .getValue ();
572
+ if (bigIndex .compareTo (BigInteger .valueOf (Integer .MIN_VALUE )) == -1 ) {
573
+ where = 0 ;
574
+ } else if (bigIndex .compareTo (BigInteger .valueOf (Integer .MAX_VALUE )) == 1 ) {
575
+ where = Integer .MAX_VALUE ;
576
+ } else {
577
+ where = bigIndex .intValue ();
578
+ }
579
+ return where ;
580
+ }
581
+
577
582
private static int normalizeIndex (int index , int len ) {
578
583
int idx = index ;
579
584
if (idx < 0 ) {
0 commit comments