Remove an unnecessary allocation from BigInt powmod

This commit is contained in:
Nathan Sashihara 2020-06-10 19:29:44 -07:00 committed by The Dlang Bot
parent a3c3ea74e3
commit 4edc8c8922

View file

@ -2312,12 +2312,13 @@ BigInt powmod(BigInt base, BigInt exponent, BigInt modulus) pure nothrow @safe
while (exponent)
{
if (exponent & 1)
if (exponent.data.peekUint(0) & 1)
{
result = (result * base) % modulus;
}
base = ((base % modulus) * (base % modulus)) % modulus;
auto tmp = base % modulus;
base = (tmp * tmp) % modulus;
exponent >>= 1;
}