@@ -477,24 +477,96 @@ protected boolean isKnownStorage(PList list) {
477
477
@ GenerateNodeFactory
478
478
public abstract static class ListExtendNode extends PythonBuiltinNode {
479
479
480
- @ Specialization
481
- public PList extend (PList list , Object source ,
480
+ @ Specialization (guards = {"isIntStorage(list)" , "isIntStorage(source)" })
481
+ public PNone extendIntInt (PList list , PList source ) {
482
+ IntSequenceStorage target = (IntSequenceStorage ) list .getSequenceStorage ();
483
+ IntSequenceStorage what = list != source
484
+ ? (IntSequenceStorage ) source .getSequenceStorage ()
485
+ : (IntSequenceStorage ) source .getSequenceStorage ().copy ();
486
+ int [] array = what .getInternalIntArray ();
487
+ for (int i = 0 ; i < what .length (); i ++) {
488
+ target .appendInt (array [i ]);
489
+ }
490
+ return PNone .NONE ;
491
+ }
492
+
493
+ @ Specialization (guards = {"isLongStorage(list)" , "isIntStorage(source)" })
494
+ public PNone extendLongInt (PList list , PList source ) {
495
+ LongSequenceStorage target = (LongSequenceStorage ) list .getSequenceStorage ();
496
+ IntSequenceStorage what = list != source
497
+ ? (IntSequenceStorage ) source .getSequenceStorage ()
498
+ : (IntSequenceStorage ) source .getSequenceStorage ().copy ();
499
+ int [] array = what .getInternalIntArray ();
500
+ for (int i = 0 ; i < what .length (); i ++) {
501
+ target .appendLong (array [i ]);
502
+ }
503
+ return PNone .NONE ;
504
+ }
505
+
506
+ @ Specialization (guards = {"isLongStorage(list)" , "isLongStorage(source)" })
507
+ public PNone extendLongLong (PList list , PList source ) {
508
+ LongSequenceStorage target = (LongSequenceStorage ) list .getSequenceStorage ();
509
+ LongSequenceStorage what = list != source
510
+ ? (LongSequenceStorage ) source .getSequenceStorage ()
511
+ : (LongSequenceStorage ) source .getSequenceStorage ().copy ();
512
+ long [] array = what .getInternalLongArray ();
513
+ for (int i = 0 ; i < what .length (); i ++) {
514
+ target .appendLong (array [i ]);
515
+ }
516
+ return PNone .NONE ;
517
+ }
518
+
519
+ @ Specialization (guards = {"isDoubleStorage(list)" , "isDoubleStorage(source)" })
520
+ public PNone extendDoubleDouble (PList list , PList source ) {
521
+ DoubleSequenceStorage target = (DoubleSequenceStorage ) list .getSequenceStorage ();
522
+ DoubleSequenceStorage what = list != source
523
+ ? (DoubleSequenceStorage ) source .getSequenceStorage ()
524
+ : (DoubleSequenceStorage ) source .getSequenceStorage ().copy ();
525
+ double [] array = what .getInternalDoubleArray ();
526
+ for (int i = 0 ; i < what .length (); i ++) {
527
+ target .appendDouble (array [i ]);
528
+ }
529
+ return PNone .NONE ;
530
+ }
531
+
532
+ @ Specialization (guards = {"isObjectStorage(list)" , "isObjectStorage(source)" })
533
+ public PNone extendObjectObject (PList list , PList source ) {
534
+ ObjectSequenceStorage target = (ObjectSequenceStorage ) list .getSequenceStorage ();
535
+ ObjectSequenceStorage what = list != source
536
+ ? (ObjectSequenceStorage ) source .getSequenceStorage ()
537
+ : (ObjectSequenceStorage ) source .getSequenceStorage ().copy ();
538
+ Object [] array = what .getInternalArray ();
539
+ for (int i = 0 ; i < what .length (); i ++) {
540
+ target .append (array [i ]);
541
+ }
542
+ return PNone .NONE ;
543
+ }
544
+
545
+ @ Specialization (guards = "isNotSpecialCase(list, source)" )
546
+ public PNone extend (PList list , Object source ,
482
547
@ Cached ("create()" ) GetIteratorNode getIterator ,
483
548
@ Cached ("create()" ) GetNextNode next ,
484
549
@ Cached ("createBinaryProfile()" ) ConditionProfile errorProfile ) {
485
550
486
- Object iterator = getIterator .executeWith (source );
551
+ Object workSource = list != source ? source : factory ().createList (((PList ) source ).getSequenceStorage ().copy ());
552
+ Object iterator = getIterator .executeWith (workSource );
487
553
while (true ) {
488
554
Object value ;
489
555
try {
490
556
value = next .execute (iterator );
491
557
} catch (PException e ) {
492
558
e .expectStopIteration (getCore (), errorProfile );
493
- return list ;
559
+ return PNone . NONE ;
494
560
}
495
561
list .append (value );
496
562
}
497
563
}
564
+
565
+ protected boolean isNotSpecialCase (PList list , Object source ) {
566
+ return !(source instanceof PList && (((PGuards .isIntStorage (list ) || PGuards .isLongStorage (list )) && PGuards .isIntStorage ((PList ) source )) ||
567
+ (PGuards .isLongStorage (list ) && PGuards .isLongStorage ((PList ) source )) || (PGuards .isDoubleStorage (list ) && PGuards .isDoubleStorage ((PList ) source )) ||
568
+ (PGuards .isObjectStorage (list ) && PGuards .isObjectStorage ((PList ) source ))));
569
+ }
498
570
}
499
571
500
572
// list.insert(i, x)
0 commit comments