Skip to content

Commit 6b1598d

Browse files
committed
Change some methods to return BigInt directly
1 parent f647f34 commit 6b1598d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

vm/src/obj/objint.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ impl PyInt {
2929
}
3030
}
3131

32+
impl IntoPyObject for BigInt {
33+
fn into_pyobject(self, ctx: &PyContext) -> PyResult {
34+
Ok(ctx.new_int(self))
35+
}
36+
}
37+
3238
impl PyValue for PyInt {
3339
fn required_type(ctx: &PyContext) -> PyObjectRef {
3440
ctx.int_type()
@@ -312,8 +318,8 @@ impl PyIntRef {
312318
}
313319
}
314320

315-
fn neg(self, vm: &mut VirtualMachine) -> PyObjectRef {
316-
vm.ctx.new_int(-(&self.value))
321+
fn neg(self, _vm: &mut VirtualMachine) -> BigInt {
322+
-(&self.value)
317323
}
318324

319325
fn hash(self, _vm: &mut VirtualMachine) -> u64 {
@@ -322,8 +328,8 @@ impl PyIntRef {
322328
hasher.finish()
323329
}
324330

325-
fn abs(self, vm: &mut VirtualMachine) -> PyObjectRef {
326-
vm.ctx.new_int(self.value.abs())
331+
fn abs(self, _vm: &mut VirtualMachine) -> BigInt {
332+
self.value.abs()
327333
}
328334

329335
fn round(self, _precision: OptionalArg<PyObjectRef>, _vm: &mut VirtualMachine) -> Self {
@@ -334,8 +340,8 @@ impl PyIntRef {
334340
self.value.to_f64().unwrap()
335341
}
336342

337-
fn invert(self, vm: &mut VirtualMachine) -> PyObjectRef {
338-
vm.ctx.new_int(!(&self.value))
343+
fn invert(self, _vm: &mut VirtualMachine) -> BigInt {
344+
!(&self.value)
339345
}
340346

341347
fn repr(self, _vm: &mut VirtualMachine) -> String {

0 commit comments

Comments
 (0)