@@ -1425,104 +1425,32 @@ static void doEmpty(@SuppressWarnings("unused") EmptySequenceStorage storage) {
1425
1425
1426
1426
@ Specialization
1427
1427
static void doIntStorage (IntSequenceStorage storage ) {
1428
- final int length = storage .length ();
1429
- final int [] values = storage .getInternalIntArray ();
1430
- if (length > 0 ) {
1431
- int head = 0 ;
1432
- int tail = length - 1 ;
1433
- int middle = (length - 1 ) / 2 ;
1434
-
1435
- for (; head <= middle ; head ++, tail --) {
1436
- int temp = values [head ];
1437
- values [head ] = values [tail ];
1438
- values [tail ] = temp ;
1439
- }
1440
- }
1428
+ storage .reverse ();
1441
1429
}
1442
1430
1443
1431
@ Specialization
1444
1432
static void doDoubleStorage (DoubleSequenceStorage storage ) {
1445
- final int length = storage .length ();
1446
- final double [] values = storage .getInternalDoubleArray ();
1447
- if (length > 0 ) {
1448
- int head = 0 ;
1449
- int tail = length - 1 ;
1450
- int middle = (length - 1 ) / 2 ;
1451
-
1452
- for (; head <= middle ; head ++, tail --) {
1453
- double temp = values [head ];
1454
- values [head ] = values [tail ];
1455
- values [tail ] = temp ;
1456
- }
1457
- }
1433
+ storage .reverse ();
1458
1434
}
1459
1435
1460
1436
@ Specialization
1461
1437
static void doLongStorage (LongSequenceStorage storage ) {
1462
- final int length = storage .length ();
1463
- final long [] values = storage .getInternalLongArray ();
1464
- if (length > 0 ) {
1465
- int head = 0 ;
1466
- int tail = length - 1 ;
1467
- int middle = (length - 1 ) / 2 ;
1468
-
1469
- for (; head <= middle ; head ++, tail --) {
1470
- long temp = values [head ];
1471
- values [head ] = values [tail ];
1472
- values [tail ] = temp ;
1473
- }
1474
- }
1438
+ storage .reverse ();
1475
1439
}
1476
1440
1477
1441
@ Specialization
1478
1442
static void doByteStorage (ByteSequenceStorage storage ) {
1479
- final int length = storage .length ();
1480
- final byte [] values = storage .getInternalByteArray ();
1481
- if (length > 0 ) {
1482
- int head = 0 ;
1483
- int tail = length - 1 ;
1484
- int middle = (length - 1 ) / 2 ;
1485
-
1486
- for (; head <= middle ; head ++, tail --) {
1487
- byte temp = values [head ];
1488
- values [head ] = values [tail ];
1489
- values [tail ] = temp ;
1490
- }
1491
- }
1443
+ storage .reverse ();
1492
1444
}
1493
1445
1494
1446
@ Specialization
1495
1447
static void doObjectStorage (ObjectSequenceStorage storage ) {
1496
- final int length = storage .length ();
1497
- final Object [] values = storage .getInternalArray ();
1498
- if (length > 0 ) {
1499
- int head = 0 ;
1500
- int tail = length - 1 ;
1501
- int middle = (length - 1 ) / 2 ;
1502
-
1503
- for (; head <= middle ; head ++, tail --) {
1504
- Object temp = values [head ];
1505
- values [head ] = values [tail ];
1506
- values [tail ] = temp ;
1507
- }
1508
- }
1448
+ storage .reverse ();
1509
1449
}
1510
1450
1511
1451
@ Specialization
1512
1452
static void doBoolStorage (BoolSequenceStorage storage ) {
1513
- final int length = storage .length ();
1514
- final boolean [] values = storage .getInternalBoolArray ();
1515
- if (length > 0 ) {
1516
- int head = 0 ;
1517
- int tail = length - 1 ;
1518
- int middle = (length - 1 ) / 2 ;
1519
-
1520
- for (; head <= middle ; head ++, tail --) {
1521
- boolean temp = values [head ];
1522
- values [head ] = values [tail ];
1523
- values [tail ] = temp ;
1524
- }
1525
- }
1453
+ storage .reverse ();
1526
1454
}
1527
1455
1528
1456
@ Specialization
@@ -3182,7 +3110,6 @@ private static int computeNewCapacity(int cap) {
3182
3110
@ GenerateUncached
3183
3111
@ GenerateInline
3184
3112
@ GenerateCached (false )
3185
- @ ImportStatic (SequenceStorageBaseNode .class )
3186
3113
public abstract static class CopyNode extends Node {
3187
3114
3188
3115
public abstract SequenceStorage execute (Node node , SequenceStorage s );
@@ -3223,7 +3150,7 @@ static SequenceStorage doBoolean(BoolSequenceStorage storage) {
3223
3150
3224
3151
@ Specialization
3225
3152
static SequenceStorage doObject (ObjectSequenceStorage storage ) {
3226
- return new ObjectSequenceStorage (PythonUtils .arrayCopyOf (storage .getCopyOfInternalArray (), storage .length ()));
3153
+ return new ObjectSequenceStorage (PythonUtils .arrayCopyOf (storage .getInternalArray (), storage .length ()));
3227
3154
}
3228
3155
3229
3156
@ Specialization
@@ -3738,100 +3665,56 @@ public final SequenceStorage executeCached(ArrayBasedSequenceStorage storage, in
3738
3665
}
3739
3666
3740
3667
@ Specialization
3741
- static SequenceStorage doIntStorage (Node inliningTarget , IntSequenceStorage storage , int idx , int value ,
3742
- @ Shared @ Cached EnsureCapacityNode ensureCapacityNode ) {
3743
- final int length = storage .length ();
3744
- ensureCapacityNode .execute (inliningTarget , storage , length + 1 );
3745
- final int [] values = storage .getInternalIntArray ();
3746
-
3747
- // shifting tail to the right by one slot
3748
- for (int i = values .length - 1 ; i > idx ; i --) {
3749
- values [i ] = values [i - 1 ];
3750
- }
3751
-
3752
- values [idx ] = value ;
3753
- storage .incLength ();
3668
+ static SequenceStorage doIntStorage (IntSequenceStorage storage , int idx , int value ) {
3669
+ storage .insertIntItem (idx , value );
3754
3670
return storage ;
3755
3671
}
3756
3672
3757
3673
@ Specialization
3758
- static SequenceStorage doDoubleStorage (Node inliningTarget , DoubleSequenceStorage storage , int idx , double value ,
3759
- @ Shared @ Cached EnsureCapacityNode ensureCapacityNode ) {
3760
- final int length = storage .length ();
3761
- ensureCapacityNode .execute (inliningTarget , storage , length + 1 );
3762
- final double [] values = storage .getInternalDoubleArray ();
3763
-
3764
- // shifting tail to the right by one slot
3765
- for (int i = values .length - 1 ; i > idx ; i --) {
3766
- values [i ] = values [i - 1 ];
3767
- }
3768
-
3769
- values [idx ] = value ;
3770
- storage .incLength ();
3674
+ static SequenceStorage doDoubleStorage (DoubleSequenceStorage storage , int idx , double value ) {
3675
+ storage .insertDoubleItem (idx , value );
3771
3676
return storage ;
3772
3677
}
3773
3678
3774
3679
@ Specialization
3775
- static SequenceStorage doLongWithLongStorage (Node inliningTarget , LongSequenceStorage storage , int idx , long value ,
3776
- @ Shared @ Cached EnsureCapacityNode ensureCapacityNode ) {
3777
- return insertLong ( inliningTarget , storage , idx , value , ensureCapacityNode ) ;
3680
+ static SequenceStorage doLongWithLongStorage (LongSequenceStorage storage , int idx , long value ) {
3681
+ storage . insertLongItem ( idx , value );
3682
+ return storage ;
3778
3683
}
3779
3684
3780
3685
@ Specialization
3781
- static SequenceStorage doIntWithLongStorage (Node inliningTarget , LongSequenceStorage storage , int idx , int value ,
3782
- @ Shared @ Cached EnsureCapacityNode ensureCapacityNode ) {
3783
- return insertLong ( inliningTarget , storage , idx , value , ensureCapacityNode ) ;
3686
+ static SequenceStorage doIntWithLongStorage (LongSequenceStorage storage , int idx , int value ) {
3687
+ storage . insertLongItem ( idx , value );
3688
+ return storage ;
3784
3689
}
3785
3690
3786
3691
@ Specialization
3787
- static SequenceStorage doBigIntWithLongStorage (Node inliningTarget , LongSequenceStorage storage , int idx , BigInteger value ,
3788
- @ Shared @ Cached EnsureCapacityNode ensureCapacityNode ) {
3789
- return insertLong ( inliningTarget , storage , idx , PInt . longValue ( value ), ensureCapacityNode ) ;
3692
+ static SequenceStorage doBigIntWithLongStorage (LongSequenceStorage storage , int idx , BigInteger value ) {
3693
+ storage . insertLongItem ( idx , PInt . longValue ( value ));
3694
+ return storage ;
3790
3695
}
3791
3696
3792
3697
@ Specialization
3793
- static SequenceStorage doByteWithByteStorage (Node inliningTarget , ByteSequenceStorage storage , int idx , byte value ,
3794
- @ Shared @ Cached EnsureCapacityNode ensureCapacityNode ) {
3795
- return insertByte ( inliningTarget , storage , idx , value , ensureCapacityNode ) ;
3698
+ static SequenceStorage doByteWithByteStorage (ByteSequenceStorage storage , int idx , byte value ) {
3699
+ storage . insertByteItem ( idx , value );
3700
+ return storage ;
3796
3701
}
3797
3702
3798
3703
@ Specialization
3799
- static SequenceStorage doIntWithByteStorage (Node inliningTarget , ByteSequenceStorage storage , int idx , int value ,
3800
- @ Shared @ Cached EnsureCapacityNode ensureCapacityNode ) {
3801
- return insertByte ( inliningTarget , storage , idx , ( byte ) value , ensureCapacityNode ) ;
3704
+ static SequenceStorage doIntWithByteStorage (ByteSequenceStorage storage , int idx , int value ) {
3705
+ storage . insertByteItem ( idx , ( byte ) value );
3706
+ return storage ;
3802
3707
}
3803
3708
3804
3709
@ Specialization
3805
- static SequenceStorage doBoolStorage (Node inliningTarget , BoolSequenceStorage storage , int idx , boolean value ,
3806
- @ Shared @ Cached EnsureCapacityNode ensureCapacityNode ) {
3807
- final int length = storage .length ();
3808
- ensureCapacityNode .execute (inliningTarget , storage , length + 1 );
3809
- final boolean [] values = storage .getInternalBoolArray ();
3810
-
3811
- // shifting tail to the right by one slot
3812
- for (int i = values .length - 1 ; i > idx ; i --) {
3813
- values [i ] = values [i - 1 ];
3814
- }
3815
-
3816
- values [idx ] = value ;
3817
- storage .incLength ();
3710
+ static SequenceStorage doBoolStorage (BoolSequenceStorage storage , int idx , boolean value ) {
3711
+ storage .insertBoolItem (idx , value );
3818
3712
return storage ;
3819
3713
}
3820
3714
3821
3715
@ Specialization
3822
- static SequenceStorage doObjectStorage (Node inliningTarget , ObjectSequenceStorage storage , int idx , Object value ,
3823
- @ Shared @ Cached EnsureCapacityNode ensureCapacityNode ) {
3824
- final int length = storage .length ();
3825
- ensureCapacityNode .execute (inliningTarget , storage , length + 1 );
3826
- final Object [] values = storage .getInternalArray ();
3827
-
3828
- // shifting tail to the right by one slot
3829
- for (int i = values .length - 1 ; i > idx ; i --) {
3830
- values [i ] = values [i - 1 ];
3831
- }
3832
-
3833
- values [idx ] = assertNoJavaString (value );
3834
- storage .incLength ();
3716
+ static SequenceStorage doObjectStorage (ObjectSequenceStorage storage , int idx , Object value ) {
3717
+ storage .insertItem (idx , value );
3835
3718
return storage ;
3836
3719
}
3837
3720
@@ -3846,36 +3729,6 @@ static SequenceStorage doGeneralization(ArrayBasedSequenceStorage storage, int i
3846
3729
ObjectSequenceStorage newStorage = storage .generalize ();
3847
3730
return recursiveNode .executeCached (newStorage , idx , value );
3848
3731
}
3849
-
3850
- private static SequenceStorage insertLong (Node inliningTarget , LongSequenceStorage storage , int idx , long value , EnsureCapacityNode ensureCapacityNode ) {
3851
- final int length = storage .length ();
3852
- ensureCapacityNode .execute (inliningTarget , storage , length + 1 );
3853
- final long [] values = storage .getInternalLongArray ();
3854
-
3855
- // shifting tail to the right by one slot
3856
- for (int i = values .length - 1 ; i > idx ; i --) {
3857
- values [i ] = values [i - 1 ];
3858
- }
3859
-
3860
- values [idx ] = value ;
3861
- storage .incLength ();
3862
- return storage ;
3863
- }
3864
-
3865
- private static SequenceStorage insertByte (Node inliningTarget , ByteSequenceStorage storage , int idx , byte value , EnsureCapacityNode ensureCapacityNode ) {
3866
- final int length = storage .length ();
3867
- ensureCapacityNode .execute (inliningTarget , storage , length + 1 );
3868
- final byte [] values = storage .getInternalByteArray ();
3869
-
3870
- // shifting tail to the right by one slot
3871
- for (int i = values .length - 1 ; i > idx ; i --) {
3872
- values [i ] = values [i - 1 ];
3873
- }
3874
-
3875
- values [idx ] = value ;
3876
- storage .incLength ();
3877
- return storage ;
3878
- }
3879
3732
}
3880
3733
3881
3734
@ GenerateUncached
0 commit comments