Use built-in iteration functions more

This commit is contained in:
François Garillot
2019-12-02 07:28:49 -08:00
committed by Pratyush Mishra
parent c42c7dd98a
commit 53a51eb4dc
5 changed files with 6 additions and 9 deletions

View File

@@ -144,9 +144,9 @@ impl<G: Group, W: PedersenWindow> FixedLengthCRH for BoweHopwoodPedersenCRH<G, W
} }
encoded encoded
}) })
.reduce(|| G::zero(), |a, b| a + &b) .reduce(G::zero, |a, b| a + &b)
}) })
.reduce(|| G::zero(), |a, b| a + &b); .reduce(G::zero, |a, b| a + &b);
end_timer!(eval_time); end_timer!(eval_time);
Ok(result) Ok(result)

View File

@@ -111,7 +111,7 @@ impl<G: Group, W: PedersenWindow> FixedLengthCRH for PedersenCRH<G, W> {
} }
encoded encoded
}) })
.reduce(|| G::zero(), |a, b| a + &b); .reduce(G::zero, |a, b| a + &b);
end_timer!(eval_time); end_timer!(eval_time);
Ok(result) Ok(result)

View File

@@ -586,7 +586,7 @@ impl Boolean {
// This is part of a run of ones. // This is part of a run of ones.
current_run.push(a.clone()); current_run.push(a.clone());
} else { } else {
if current_run.len() > 0 { if !current_run.is_empty() {
// This is the start of a run of zeros, but we need // This is the start of a run of zeros, but we need
// to k-ary AND against `last_run` first. // to k-ary AND against `last_run` first.

View File

@@ -405,7 +405,7 @@ mod test {
assert_eq!(a_inv.get_value().unwrap(), a_native.inverse().unwrap()); assert_eq!(a_inv.get_value().unwrap(), a_native.inverse().unwrap());
// a * a * a = a^3 // a * a * a = a^3
let bits = BitIterator::new([0x3]) let bits = BitIterator::new([0x3])
.map(|bit| Boolean::constant(bit)) .map(Boolean::constant)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
assert_eq!( assert_eq!(
a_native * &(a_native * &a_native), a_native * &(a_native * &a_native),

View File

@@ -71,9 +71,6 @@ pub trait Assignment<T> {
impl<T> Assignment<T> for Option<T> { impl<T> Assignment<T> for Option<T> {
fn get(self) -> Result<T, r1cs_core::SynthesisError> { fn get(self) -> Result<T, r1cs_core::SynthesisError> {
match self { self.ok_or_else(|| { r1cs_core::SynthesisError::AssignmentMissing })
Some(v) => Ok(v),
None => Err(r1cs_core::SynthesisError::AssignmentMissing),
}
} }
} }