Skip to content

Commit 913727c

Browse files
lovesholeganza
authored andcommitted
Remove redundant add operation and allocate vector beforehand (#251)
* remove redundant add operation and allocate vector beforehand Signed-off-by: lovesh harchandani <[email protected]> * remove redundant iterator creation Signed-off-by: lovesh harchandani <[email protected]>
1 parent 458a24b commit 913727c

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/r1cs/verifier.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,7 @@ impl<'a, 'b> Verifier<'a, 'b> {
373373
let u_for_g = iter::repeat(Scalar::one())
374374
.take(n1)
375375
.chain(iter::repeat(u).take(n2 + pad));
376-
let u_for_h = iter::repeat(Scalar::one())
377-
.take(n1)
378-
.chain(iter::repeat(u).take(n2 + pad));
376+
let u_for_h = u_for_g.clone();
379377

380378
// define parameters for P check
381379
let g_scalars = yneg_wR

src/util.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ pub fn exp_iter(x: Scalar) -> ScalarExp {
6262
}
6363

6464
pub fn add_vec(a: &[Scalar], b: &[Scalar]) -> Vec<Scalar> {
65-
let mut out = Vec::new();
6665
if a.len() != b.len() {
6766
// throw some error
6867
println!("lengths of vectors don't match for vector addition");
6968
}
69+
let mut out = vec![Scalar::zero(); b.len()];
7070
for i in 0..a.len() {
71-
out.push(a[i] + b[i]);
71+
out[i] = a[i] + b[i];
7272
}
7373
out
7474
}
@@ -98,7 +98,7 @@ impl VecPoly1 {
9898
let n = self.0.len();
9999
let mut out = vec![Scalar::zero(); n];
100100
for i in 0..n {
101-
out[i] += self.0[i] + self.1[i] * x;
101+
out[i] = self.0[i] + self.1[i] * x;
102102
}
103103
out
104104
}
@@ -143,7 +143,7 @@ impl VecPoly3 {
143143
let n = self.0.len();
144144
let mut out = vec![Scalar::zero(); n];
145145
for i in 0..n {
146-
out[i] += self.0[i] + x * (self.1[i] + x * (self.2[i] + x * self.3[i]));
146+
out[i] = self.0[i] + x * (self.1[i] + x * (self.2[i] + x * self.3[i]));
147147
}
148148
out
149149
}

0 commit comments

Comments
 (0)