mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 14:10:30 +03:00
Remove an unnecessary allocation from BigInt powmod
This commit is contained in:
parent
a3c3ea74e3
commit
4edc8c8922
1 changed files with 3 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue