cut down modpow to keep fast path smaller
@@ -425,24 +425,15 @@ impl PyInt {
self.int_op(other, |a, b| a & b, vm)
}
- #[pymethod(magic)]
- fn pow(
- &self,
- other: PyObjectRef,
- mod_val: OptionalOption<PyObjectRef>,
- vm: &VirtualMachine,
- ) -> PyResult {
- match mod_val.flatten() {
- Some(int_ref) => {
- let int = match int_ref.payload_if_subclass::<PyInt>(vm) {
- Some(val) => val,
+ fn modpow(&self, other: PyObjectRef, modulus: PyObjectRef, vm: &VirtualMachine) -> PyResult {
+ let modulus = match modulus.payload_if_subclass::<PyInt>(vm) {
+ Some(val) => val.as_bigint(),
None => return Ok(vm.ctx.not_implemented()),
};
-
- let modulus = int.as_bigint();
if modulus.is_zero() {
return Err(vm.new_value_error("pow() 3rd argument cannot be 0".to_owned()));
}
+
self.general_op(
other,
|a, b| {
@@ -481,6 +472,16 @@ impl PyInt {
vm,
)
}
+
+ #[pymethod(magic)]
+ fn pow(
+ &self,
+ other: PyObjectRef,
+ r#mod: OptionalOption<PyObjectRef>,
+ vm: &VirtualMachine,
+ ) -> PyResult {
+ match r#mod.flatten() {
+ Some(modulus) => self.modpow(other, modulus, vm),
None => self.general_op(other, |a, b| inner_pow(a, b, vm), vm),
}
}
