Skip to content

Commit 991bae4

Browse files
committed
Fix: deque.insert with negative index
1 parent b6d1ad1 commit 991bae4

File tree

1 file changed

+16
-7
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque

1 file changed

+16
-7
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeBuiltins.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -475,15 +475,15 @@ PNone doGeneric(PDeque self, int index, Object value) {
475475
self.append(value);
476476
} else if (index <= -n || index == 0) {
477477
self.appendLeft(value);
478-
}
479-
480-
DequeRotateNode.doLeft(self, -index);
481-
if (index < 0) {
482-
self.append(value);
483478
} else {
484-
self.appendLeft(value);
479+
DequeRotateNode.rotate(self, -index);
480+
if (index < 0) {
481+
self.append(value);
482+
} else {
483+
self.appendLeft(value);
484+
}
485+
DequeRotateNode.rotate(self, index);
485486
}
486-
DequeRotateNode.doRight(self, index);
487487

488488
return PNone.NONE;
489489
}
@@ -619,6 +619,15 @@ static PNone doLeft(PDeque self, int n) {
619619
}
620620
return PNone.NONE;
621621
}
622+
623+
static PNone rotate(PDeque self, int n) {
624+
if (n < 0) {
625+
doLeft(self, n);
626+
} else {
627+
doRight(self, n);
628+
}
629+
return PNone.NONE;
630+
}
622631
}
623632

624633
// SEQUENCE METHODS

0 commit comments

Comments
 (0)