@@ -628,45 +628,46 @@ protected static GetItemNode createGetItem() {
628
628
@ GenerateNodeFactory
629
629
@ ImportStatic (SpecialMethodNames .class )
630
630
abstract static class SetItemNode extends PythonTernaryBuiltinNode {
631
- @ Child private SequenceStorageNodes .SetItemNode setItemNode ;
632
-
633
- @ Specialization (guards = "!isMemoryView(value)" )
634
- PNone doBasic (PByteArray self , Object idx , Object value ) {
635
- getSetItemNode ().execute (self .getSequenceStorage (), idx , value );
631
+ @ Specialization (guards = {"!isPSlice(idx)" , "!isMemoryView(value)" })
632
+ PNone doItem (PByteArray self , Object idx , Object value ,
633
+ @ Cached ("createSetItem()" ) SequenceStorageNodes .SetItemNode setItemNode ) {
634
+ setItemNode .execute (self .getSequenceStorage (), idx , value );
636
635
return PNone .NONE ;
637
636
}
638
637
639
638
@ Specialization
640
639
PNone doSliceMemoryview (PByteArray self , PSlice slice , PMemoryView value ,
641
640
@ Cached ("create(TOBYTES)" ) LookupAndCallUnaryNode callToBytesNode ,
642
- @ Cached ("createBinaryProfile()" ) ConditionProfile isBytesProfile ) {
641
+ @ Cached ("createBinaryProfile()" ) ConditionProfile isBytesProfile ,
642
+ @ Cached ("createSetSlice()" ) SequenceStorageNodes .SetItemNode setItemNode ) {
643
643
Object bytesObj = callToBytesNode .executeObject (value );
644
644
if (isBytesProfile .profile (bytesObj instanceof PBytes )) {
645
- doBasic (self , slice , bytesObj );
645
+ doSlice (self , slice , bytesObj , setItemNode );
646
646
return PNone .NONE ;
647
647
}
648
648
throw raise (SystemError , "could not get bytes of memoryview" );
649
649
}
650
650
651
- // TODO error message
652
- // @Specialization(guards = "isScalar(value)")
653
- // @SuppressWarnings("unused")
654
- // PNone doSliceScalar(PByteArray self, PSlice slice, Object value) {
655
- // throw raise(TypeError, "can assign only bytes, buffers, or iterables of ints in range(0, 256)");
656
- // }
651
+ @ Specialization (guards = "!isMemoryView(value)" )
652
+ PNone doSlice (PByteArray self , PSlice idx , Object value ,
653
+ @ Cached ("createSetSlice()" ) SequenceStorageNodes .SetItemNode setItemNode ) {
654
+ // this is really just a separate specialization due to the different error message
655
+ setItemNode .execute (self .getSequenceStorage (), idx , value );
656
+ return PNone .NONE ;
657
+ }
657
658
658
659
@ Fallback
659
660
@ SuppressWarnings ("unused" )
660
661
Object doGeneric (Object self , Object idx , Object value ) {
661
662
return PNotImplemented .NOT_IMPLEMENTED ;
662
663
}
663
664
664
- private SequenceStorageNodes .SetItemNode getSetItemNode () {
665
- if ( setItemNode == null ) {
666
- CompilerDirectives . transferToInterpreterAndInvalidate ();
667
- setItemNode = insert ( SequenceStorageNodes . SetItemNode . create ( NormalizeIndexNode . forBytearray (), "an integer is required" ));
668
- }
669
- return setItemNode ;
665
+ protected SequenceStorageNodes .SetItemNode createSetItem () {
666
+ return SequenceStorageNodes . SetItemNode . create ( NormalizeIndexNode . forBytearray (), "an integer is required" );
667
+ }
668
+
669
+ protected SequenceStorageNodes . SetItemNode createSetSlice () {
670
+ return SequenceStorageNodes . SetItemNode . create ( NormalizeIndexNode . forBytearray (), "can assign only bytes, buffers, or iterables of ints in range(0, 256)" ) ;
670
671
}
671
672
672
673
protected static boolean isMemoryView (Object value ) {
0 commit comments