mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-08-01 12:51:30 +00:00
For performance, don't double/square until we've seen a bit.
This commit is contained in:
@@ -475,9 +475,15 @@ macro_rules! curve_impl {
|
|||||||
fn mul_assign<S: Into<<Self::Scalar as PrimeField>::Repr>>(&mut self, other: S) {
|
fn mul_assign<S: Into<<Self::Scalar as PrimeField>::Repr>>(&mut self, other: S) {
|
||||||
let mut res = Self::zero();
|
let mut res = Self::zero();
|
||||||
|
|
||||||
|
let mut found_one = false;
|
||||||
|
|
||||||
for i in BitIterator::new(other.into())
|
for i in BitIterator::new(other.into())
|
||||||
{
|
{
|
||||||
res.double();
|
if found_one {
|
||||||
|
res.double();
|
||||||
|
} else {
|
||||||
|
found_one = i;
|
||||||
|
}
|
||||||
|
|
||||||
if i {
|
if i {
|
||||||
res.add_assign(self);
|
res.add_assign(self);
|
||||||
|
@@ -219,8 +219,15 @@ pub trait Field: Sized +
|
|||||||
{
|
{
|
||||||
let mut res = Self::one();
|
let mut res = Self::one();
|
||||||
|
|
||||||
|
let mut found_one = false;
|
||||||
|
|
||||||
for i in BitIterator::new(exp) {
|
for i in BitIterator::new(exp) {
|
||||||
res.square();
|
if found_one {
|
||||||
|
res.square();
|
||||||
|
} else {
|
||||||
|
found_one = i;
|
||||||
|
}
|
||||||
|
|
||||||
if i {
|
if i {
|
||||||
res.mul_assign(self);
|
res.mul_assign(self);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user