@@ -675,17 +675,11 @@ protected static GetItemNode createGetItem() {
675
675
@ GenerateNodeFactory
676
676
@ ImportStatic (SpecialMethodNames .class )
677
677
abstract static class SetItemNode extends PythonTernaryBuiltinNode {
678
- @ Child private SequenceStorageNodes .NormalizeIndexNode normalize ;
679
-
680
- @ Specialization
681
- PNone doInt (PByteArray self , int idx , Object value ) {
682
- self .setItemNormalized (ensureNormalize ().execute (idx , self .len ()), value );
683
- return PNone .NONE ;
684
- }
678
+ @ Child private SequenceStorageNodes .SetItemNode setItemNode ;
685
679
686
- @ Specialization
687
- PNone doSliceSequence (PByteArray self , PSlice slice , PSequence value ) {
688
- self .setSlice ( slice , value );
680
+ @ Specialization ( guards = "!isMemoryView(value)" )
681
+ PNone doBasic (PByteArray self , Object idx , Object value ) {
682
+ getSetItemNode (). execute ( self .getSequenceStorage (), idx , value );
689
683
return PNone .NONE ;
690
684
}
691
685
@@ -695,62 +689,35 @@ PNone doSliceMemoryview(PByteArray self, PSlice slice, PMemoryView value,
695
689
@ Cached ("createBinaryProfile()" ) ConditionProfile isBytesProfile ) {
696
690
Object bytesObj = callToBytesNode .executeObject (value );
697
691
if (isBytesProfile .profile (bytesObj instanceof PBytes )) {
698
- doSliceSequence (self , slice , ( PBytes ) bytesObj );
692
+ doBasic (self , slice , bytesObj );
699
693
return PNone .NONE ;
700
694
}
701
695
throw raise (SystemError , "could not get bytes of memoryview" );
702
696
}
703
697
704
- @ Specialization (guards = "isScalar(value)" )
705
- @ SuppressWarnings ("unused" )
706
- PNone doSliceScalar (PByteArray self , PSlice slice , Object value ) {
707
- throw raise (TypeError , "can assign only bytes, buffers, or iterables of ints in range(0, 256)" );
708
- }
709
-
710
- @ Specialization (rewriteOn = ArithmeticException .class )
711
- public Object doLong (PByteArray primary , long idx , Object value ) {
712
- return doInt (primary , PInt .intValueExact (idx ), value );
713
- }
714
-
715
- @ Specialization (replaces = "doLong" )
716
- public Object doLongOvf (PByteArray primary , long idx , Object value ) {
717
- try {
718
- return doInt (primary , PInt .intValueExact (idx ), value );
719
- } catch (ArithmeticException e ) {
720
- throw raiseIndexError ();
721
- }
722
- }
723
-
724
- @ Specialization (rewriteOn = ArithmeticException .class )
725
- public Object doPInt (PByteArray primary , PInt idx , Object value ) {
726
- return doInt (primary , idx .intValueExact (), value );
727
- }
728
-
729
- @ Specialization (replaces = "doPInt" )
730
- public Object doPIntOvf (PByteArray primary , PInt idx , Object value ) {
731
- try {
732
- return doInt (primary , idx .intValueExact (), value );
733
- } catch (ArithmeticException e ) {
734
- throw raiseIndexError ();
735
- }
736
- }
698
+ // TODO error message
699
+ // @Specialization(guards = "isScalar(value)")
700
+ // @SuppressWarnings("unused")
701
+ // PNone doSliceScalar(PByteArray self, PSlice slice, Object value) {
702
+ // throw raise(TypeError, "can assign only bytes, buffers, or iterables of ints in range(0, 256)");
703
+ // }
737
704
738
705
@ Fallback
739
706
@ SuppressWarnings ("unused" )
740
707
Object doGeneric (Object self , Object idx , Object value ) {
741
708
return PNotImplemented .NOT_IMPLEMENTED ;
742
709
}
743
710
744
- private SequenceStorageNodes .NormalizeIndexNode ensureNormalize () {
745
- if (normalize == null ) {
711
+ private SequenceStorageNodes .SetItemNode getSetItemNode () {
712
+ if (setItemNode == null ) {
746
713
CompilerDirectives .transferToInterpreterAndInvalidate ();
747
- normalize = insert (SequenceStorageNodes .NormalizeIndexNode .forArrayAssign ( ));
714
+ setItemNode = insert (SequenceStorageNodes .SetItemNode . create ( NormalizeIndexNode .forBytearray () ));
748
715
}
749
- return normalize ;
716
+ return setItemNode ;
750
717
}
751
718
752
- protected boolean isScalar (Object value ) {
753
- return !( value instanceof PSequence || value instanceof PMemoryView ) ;
719
+ protected static boolean isMemoryView (Object value ) {
720
+ return value instanceof PMemoryView ;
754
721
}
755
722
}
756
723
0 commit comments