-
Notifications
You must be signed in to change notification settings - Fork 322
Description
In the whole codebase, there is a standard which is to include the suffix in_place
on operations which modify the value passed as a mutable parameter. For example here:
algebra/ec/src/models/bn/g2.rs
Lines 53 to 77 in cc2ad8c
fn double_in_place(&mut self, two_inv: &P::Fp) -> EllCoeff<P> { | |
// Formula for line function when working with | |
// homogeneous projective coordinates. | |
let mut a = self.x * &self.y; | |
a.mul_assign_by_fp(two_inv); | |
let b = self.y.square(); | |
let c = self.z.square(); | |
let e = P::G2Config::COEFF_B * &(c.double() + &c); | |
let f = e.double() + &e; | |
let mut g = b + &f; | |
g.mul_assign_by_fp(two_inv); | |
let h = (self.y + &self.z).square() - &(b + &c); | |
let i = e - &b; | |
let j = self.x.square(); | |
let e_square = e.square(); | |
self.x = a * &(b - &f); | |
self.y = g.square() - &(e_square.double() + &e_square); | |
self.z = b * &h; | |
match P::TWIST_TYPE { | |
TwistType::M => (i, j.double() + &j, -h), | |
TwistType::D => (-h, j.double() + &j, i), | |
} | |
} |
We know from the function name that the self
mutable will be modified.
However similar operations are performed in the BigInteger
trait like:
algebra/ff/src/biginteger/mod.rs
Line 1062 in cc2ad8c
fn mul2(&mut self) -> bool; |
or
algebra/ff/src/biginteger/mod.rs
Line 1037 in cc2ad8c
fn sub_with_borrow(&mut self, other: &Self) -> bool; |
without including the in_place
suffix. For readability and consistency, it could be nice to include this suffix for all the BigInteger
operations concerned by this type of logic.