The internal functions currently take a var BigInt argument as first parameter, which is used to store the result (essentially an out parameter). I suppose that is so that a buffer can be preallocated, however, that's never done afaict. In this light, it would be more ergonomic to just return a new BigInt (using the result variable).
Another possibility is instead of defining functions like func addition(a: var BigInt, b, c: BigInt) to do a = b + c, use func addition(a: var BigInt, b: BigInt) to do a += b. That would avoid copying the first argument for +=. a + b would then be implemented as result = a; result += b, but I'm not sure if that avoids a copy (I think it should, at least with ARC/ORC). (I'm just using addition as an example, the same applies to other operations).
If there is no flaw in my analysis, I'd prefer the last possibility, as I think it's the most efficient and ergonomic.
cc @narimiran @mratsim
The internal functions currently take a
var BigIntargument as first parameter, which is used to store the result (essentially an out parameter). I suppose that is so that a buffer can be preallocated, however, that's never done afaict. In this light, it would be more ergonomic to just return a newBigInt(using theresultvariable).Another possibility is instead of defining functions like
func addition(a: var BigInt, b, c: BigInt)to doa = b + c, usefunc addition(a: var BigInt, b: BigInt)to doa += b. That would avoid copying the first argument for+=.a + bwould then be implemented asresult = a; result += b, but I'm not sure if that avoids a copy (I think it should, at least with ARC/ORC). (I'm just using addition as an example, the same applies to other operations).If there is no flaw in my analysis, I'd prefer the last possibility, as I think it's the most efficient and ergonomic.
cc @narimiran @mratsim