|
2 | 2 | use std::cell::{Cell, RefCell}; |
3 | 3 | use std::convert::TryFrom; |
4 | 4 |
|
5 | | -use num_traits::ToPrimitive; |
6 | | - |
7 | 5 | use super::objbyteinner::{ |
8 | 6 | ByteInnerExpandtabsOptions, ByteInnerFindOptions, ByteInnerNewOptions, ByteInnerPaddingOptions, |
9 | 7 | ByteInnerPosition, ByteInnerSplitOptions, ByteInnerSplitlinesOptions, |
@@ -506,18 +504,13 @@ impl PyByteArrayRef { |
506 | 504 | } |
507 | 505 |
|
508 | 506 | #[pymethod(name = "insert")] |
509 | | - fn insert(self, index: PyIntRef, x: PyIntRef, vm: &VirtualMachine) -> PyResult<()> { |
| 507 | + fn insert(self, mut index: isize, x: PyIntRef, vm: &VirtualMachine) -> PyResult<()> { |
510 | 508 | let bytes = &mut self.inner.borrow_mut().elements; |
511 | 509 | let len = isize::try_from(bytes.len()) |
512 | 510 | .map_err(|_e| vm.new_overflow_error("bytearray too big".to_string()))?; |
513 | 511 |
|
514 | 512 | let x = x.as_bigint().byte_or(vm)?; |
515 | 513 |
|
516 | | - let mut index = index |
517 | | - .as_bigint() |
518 | | - .to_isize() |
519 | | - .ok_or_else(|| vm.new_overflow_error("index too big".to_string()))?; |
520 | | - |
521 | 514 | if index >= len { |
522 | 515 | bytes.push(x); |
523 | 516 | return Ok(()); |
@@ -550,17 +543,17 @@ impl PyByteArrayRef { |
550 | 543 | } |
551 | 544 |
|
552 | 545 | #[pymethod(name = "__mul__")] |
553 | | - fn repeat(self, n: PyIntRef, vm: &VirtualMachine) -> PyResult { |
| 546 | + fn repeat(self, n: isize, vm: &VirtualMachine) -> PyResult { |
554 | 547 | Ok(vm.ctx.new_bytearray(self.inner.borrow().repeat(n, vm)?)) |
555 | 548 | } |
556 | 549 |
|
557 | 550 | #[pymethod(name = "__rmul__")] |
558 | | - fn rmul(self, n: PyIntRef, vm: &VirtualMachine) -> PyResult { |
| 551 | + fn rmul(self, n: isize, vm: &VirtualMachine) -> PyResult { |
559 | 552 | self.repeat(n, vm) |
560 | 553 | } |
561 | 554 |
|
562 | 555 | #[pymethod(name = "__imul__")] |
563 | | - fn irepeat(self, n: PyIntRef, vm: &VirtualMachine) -> PyResult<()> { |
| 556 | + fn irepeat(self, n: isize, vm: &VirtualMachine) -> PyResult<()> { |
564 | 557 | self.inner.borrow_mut().irepeat(n, vm) |
565 | 558 | } |
566 | 559 |
|
|
0 commit comments