Optimize transpose_option_array

This commit is contained in:
str4d 2021-06-29 22:43:50 +01:00 committed by GitHub
parent 8dfcd7d49b
commit cbded2b821
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 8 deletions

View File

@ -3,7 +3,7 @@ use halo2::{
plonk::{Advice, Column, Error, Permutation}, plonk::{Advice, Column, Error, Permutation},
}; };
use pasta_curves::arithmetic::FieldExt; use pasta_curves::arithmetic::FieldExt;
use std::convert::TryInto; use std::array;
pub(crate) mod cond_swap; pub(crate) mod cond_swap;
pub(crate) mod enable_flag; pub(crate) mod enable_flag;
@ -89,13 +89,11 @@ where
pub fn transpose_option_array<T: Copy + std::fmt::Debug, const LEN: usize>( pub fn transpose_option_array<T: Copy + std::fmt::Debug, const LEN: usize>(
option_array: Option<[T; LEN]>, option_array: Option<[T; LEN]>,
) -> [Option<T>; LEN] { ) -> [Option<T>; LEN] {
let mut ret = [None; LEN];
if let Some(arr) = option_array { if let Some(arr) = option_array {
arr.iter() for (entry, value) in ret.iter_mut().zip(array::IntoIter::new(arr)) {
.map(|el| Some(*el)) *entry = Some(value);
.collect::<Vec<_>>()
.try_into()
.unwrap()
} else {
[None; LEN]
} }
} }
ret
}