Skip to content

Commit f647f34

Browse files
committed
Use Into<BigInt> instead of ToBigInt to avoid copies
1 parent 8dcea92 commit f647f34

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

vm/src/obj/objint.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@ pub struct PyInt {
2424
pub type PyIntRef = PyRef<PyInt>;
2525

2626
impl PyInt {
27-
pub fn new<T: ToBigInt>(i: T) -> Self {
28-
PyInt {
29-
// TODO: this .clone()s a BigInt, which is not what we want.
30-
value: i.to_bigint().unwrap(),
31-
}
27+
pub fn new<T: Into<BigInt>>(i: T) -> Self {
28+
PyInt { value: i.into() }
3229
}
3330
}
3431

vm/src/pyobject.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use std::ptr;
1010
use std::rc::Rc;
1111

1212
use num_bigint::BigInt;
13-
use num_bigint::ToBigInt;
1413
use num_complex::Complex64;
1514
use num_traits::{One, Zero};
1615

@@ -508,7 +507,7 @@ impl PyContext {
508507
self.new_instance(self.object(), None)
509508
}
510509

511-
pub fn new_int<T: ToBigInt>(&self, i: T) -> PyObjectRef {
510+
pub fn new_int<T: Into<BigInt>>(&self, i: T) -> PyObjectRef {
512511
PyObject::new(PyInt::new(i), self.int_type())
513512
}
514513

vm/src/vm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::pyobject::{
3232
};
3333
use crate::stdlib;
3434
use crate::sysmodule;
35-
use num_bigint::ToBigInt;
35+
use num_bigint::BigInt;
3636

3737
// use objects::objects;
3838

@@ -109,7 +109,7 @@ impl VirtualMachine {
109109
}
110110

111111
/// Create a new python int object.
112-
pub fn new_int<T: ToBigInt>(&self, i: T) -> PyObjectRef {
112+
pub fn new_int<T: Into<BigInt>>(&self, i: T) -> PyObjectRef {
113113
self.ctx.new_int(i)
114114
}
115115

0 commit comments

Comments
 (0)