Skip to content

Commit e52c8cd

Browse files
committed
Remove index normalization from array index assignment
1 parent 839b4fc commit e52c8cd

File tree

1 file changed

+8
-9
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array

1 file changed

+8
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/array/ArrayBuiltins.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ static TruffleString repr(VirtualFrame frame, PArray self,
559559
@GenerateNodeFactory
560560
abstract static class SqItemNode extends SqItemBuiltinNode {
561561
@Specialization
562-
static Object doIt(VirtualFrame frame, PArray self, int index,
562+
static Object doIt(PArray self, int index,
563563
@Bind("this") Node inliningTarget,
564564
@Cached PRaiseNode.Lazy raiseNode,
565565
@Cached ArrayNodes.GetValueNode getValueNode) {
@@ -634,22 +634,21 @@ private static PException raiseNonIntIndex(Node inliningTarget, Lazy raiseNode)
634634
abstract static class SetItemNode extends SqAssItemBuiltinNode {
635635

636636
@Specialization(guards = "!isNoValue(value)")
637-
static void setitem(VirtualFrame frame, PArray self, int idx, Object value,
637+
static void setitem(VirtualFrame frame, PArray self, int index, Object value,
638638
@Bind("this") Node inliningTarget,
639-
@Shared @Cached("forArrayAssign()") NormalizeIndexNode normalizeIndexNode,
640-
@Cached ArrayNodes.PutValueNode putValueNode) {
641-
int index = normalizeIndexNode.execute(idx, self.getLength());
639+
@Cached ArrayNodes.PutValueNode putValueNode,
640+
@Shared @Cached PRaiseNode.Lazy raiseNode) {
641+
checkBounds(inliningTarget, raiseNode, ErrorMessages.ARRAY_ASSIGN_OUT_OF_BOUNDS, index, self.getLength());
642642
putValueNode.execute(frame, inliningTarget, self, index, value);
643643
}
644644

645645
@Specialization(guards = "isNoValue(value)")
646-
static void delitem(PArray self, int idx, @SuppressWarnings("unused") Object value,
646+
static void delitem(PArray self, int index, @SuppressWarnings("unused") Object value,
647647
@Bind("this") Node inliningTarget,
648-
@Shared @Cached("forArrayAssign()") NormalizeIndexNode normalizeIndexNode,
649648
@Cached DeleteArraySliceNode deleteSliceNode,
650-
@Cached PRaiseNode.Lazy raiseNode) {
649+
@Shared @Cached PRaiseNode.Lazy raiseNode) {
650+
checkBounds(inliningTarget, raiseNode, ErrorMessages.ARRAY_ASSIGN_OUT_OF_BOUNDS, index, self.getLength());
651651
self.checkCanResize(inliningTarget, raiseNode);
652-
int index = normalizeIndexNode.execute(idx, self.getLength());
653652
deleteSliceNode.execute(inliningTarget, self, index, 1);
654653
}
655654
}

0 commit comments

Comments
 (0)