48
48
import com .oracle .graal .python .builtins .objects .iterator .PIntegerSequenceIterator ;
49
49
import com .oracle .graal .python .builtins .objects .iterator .PLongSequenceIterator ;
50
50
import com .oracle .graal .python .builtins .objects .iterator .PSequenceIterator ;
51
+ import com .oracle .graal .python .builtins .objects .range .PRange ;
51
52
import com .oracle .graal .python .builtins .objects .slice .PSlice ;
52
53
import com .oracle .graal .python .builtins .objects .str .PString ;
53
54
import com .oracle .graal .python .builtins .objects .tuple .PTuple ;
@@ -477,77 +478,38 @@ protected boolean isKnownStorage(PList list) {
477
478
@ GenerateNodeFactory
478
479
public abstract static class ListExtendNode extends PythonBuiltinNode {
479
480
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
- }
481
+ @ Specialization (guards = {"isPSequenceWithStorage(source)" }, rewriteOn = {SequenceStoreException .class })
482
+ public PNone extendSequenceStore (PList list , Object source ) throws SequenceStoreException {
483
+ SequenceStorage target = list .getSequenceStorage ();
484
+ target .extend (((PSequence ) source ).getSequenceStorage ());
529
485
return PNone .NONE ;
530
486
}
531
487
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 ]);
488
+ @ Specialization (guards = {"isPSequenceWithStorage(source)" })
489
+ public PNone extendSequence (PList list , Object source ) {
490
+ SequenceStorage eSource = ((PSequence ) source ).getSequenceStorage ();
491
+ if (eSource .length () > 0 ) {
492
+ SequenceStorage target = list .getSequenceStorage ();
493
+ try {
494
+ target .extend (eSource );
495
+ } catch (SequenceStoreException e ) {
496
+ target = target .generalizeFor (eSource .getItemNormalized (0 ));
497
+ list .setSequenceStorage (target );
498
+ try {
499
+ target .extend (eSource );
500
+ } catch (SequenceStoreException e1 ) {
501
+ throw new IllegalStateException ();
502
+ }
503
+ }
541
504
}
542
505
return PNone .NONE ;
543
506
}
544
507
545
- @ Specialization (guards = "isNotSpecialCase(list, source)" )
508
+ @ Specialization (guards = "!isPSequenceWithStorage( source)" )
546
509
public PNone extend (PList list , Object source ,
547
510
@ Cached ("create()" ) GetIteratorNode getIterator ,
548
511
@ Cached ("create()" ) GetNextNode next ,
549
512
@ Cached ("createBinaryProfile()" ) ConditionProfile errorProfile ) {
550
-
551
513
Object workSource = list != source ? source : factory ().createList (((PList ) source ).getSequenceStorage ().copy ());
552
514
Object iterator = getIterator .executeWith (workSource );
553
515
while (true ) {
@@ -562,11 +524,10 @@ public PNone extend(PList list, Object source,
562
524
}
563
525
}
564
526
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 ))));
527
+ protected boolean isPSequenceWithStorage (Object source ) {
528
+ return (source instanceof PSequence && !(source instanceof PTuple || source instanceof PRange ));
569
529
}
530
+
570
531
}
571
532
572
533
// list.insert(i, x)
0 commit comments