Skip to content

Commit 9cdb59a

Browse files
committed
Fix style.
1 parent 85f0d49 commit 9cdb59a

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -628,45 +628,46 @@ protected static GetItemNode createGetItem() {
628628
@GenerateNodeFactory
629629
@ImportStatic(SpecialMethodNames.class)
630630
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);
636635
return PNone.NONE;
637636
}
638637

639638
@Specialization
640639
PNone doSliceMemoryview(PByteArray self, PSlice slice, PMemoryView value,
641640
@Cached("create(TOBYTES)") LookupAndCallUnaryNode callToBytesNode,
642-
@Cached("createBinaryProfile()") ConditionProfile isBytesProfile) {
641+
@Cached("createBinaryProfile()") ConditionProfile isBytesProfile,
642+
@Cached("createSetSlice()") SequenceStorageNodes.SetItemNode setItemNode) {
643643
Object bytesObj = callToBytesNode.executeObject(value);
644644
if (isBytesProfile.profile(bytesObj instanceof PBytes)) {
645-
doBasic(self, slice, bytesObj);
645+
doSlice(self, slice, bytesObj, setItemNode);
646646
return PNone.NONE;
647647
}
648648
throw raise(SystemError, "could not get bytes of memoryview");
649649
}
650650

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+
}
657658

658659
@Fallback
659660
@SuppressWarnings("unused")
660661
Object doGeneric(Object self, Object idx, Object value) {
661662
return PNotImplemented.NOT_IMPLEMENTED;
662663
}
663664

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)");
670671
}
671672

672673
protected static boolean isMemoryView(Object value) {

0 commit comments

Comments
 (0)