Pārlūkot izejas kodu

Preallocate some vectors

Ian Goldberg 9 mēneši atpakaļ
vecāks
revīzija
571e13ef39
1 mainītis faili ar 3 papildinājumiem un 2 dzēšanām
  1. 3 2
      src/shine.rs

+ 3 - 2
src/shine.rs

@@ -46,14 +46,15 @@ pub struct Key {
 
 impl Key {
     pub fn keygen(n: u32, t: u32) -> Vec<Self> {
+        let delta = binom(n - 1, t - 1);
         let mut rng = rand::thread_rng();
-        let mut res: Vec<Self> = Vec::new();
+        let mut res: Vec<Self> = Vec::with_capacity(n as usize);
         for k in 1..=n {
             res.push(Self {
                 n,
                 t,
                 k,
-                secrets: Vec::new(),
+                secrets: Vec::with_capacity(delta as usize),
             });
         }
         let si = (1..=n).combinations((t - 1) as usize);