diff --git a/zkevm-circuits/src/circuit_tools/cached_region.rs b/zkevm-circuits/src/circuit_tools/cached_region.rs index 7925a81af5..c178640202 100644 --- a/zkevm-circuits/src/circuit_tools/cached_region.rs +++ b/zkevm-circuits/src/circuit_tools/cached_region.rs @@ -65,7 +65,8 @@ impl<'r, 'b, F: Field> CachedRegion<'r, 'b, F> { cb: &ConstraintBuilder, challenges: &S, ) -> Result<(), Error> { - for (offset, region_id) in self.regions.clone() { + for n in 0..self.regions.len() { + let (offset, region_id) = self.regions[n]; for stored_expression in cb.get_stored_expressions(region_id).iter() { stored_expression.assign(self, challenges, offset)?; } @@ -76,14 +77,7 @@ impl<'r, 'b, F: Field> CachedRegion<'r, 'b, F> { pub(crate) fn annotate_columns(&mut self, cell_columns: &[CellColumn]) { for c in cell_columns { self.region.name_column( - || { - format!( - "{:?} {:?}: {:?} queried", - c.cell_type.clone(), - c.index, - c.height - ) - }, + || format!("{:?} {:?}: {:?} queried", c.cell_type, c.index, c.height), c.column, ); } diff --git a/zkevm-circuits/src/circuit_tools/cell_manager.rs b/zkevm-circuits/src/circuit_tools/cell_manager.rs index 03bda945ec..468c07e9fa 100644 --- a/zkevm-circuits/src/circuit_tools/cell_manager.rs +++ b/zkevm-circuits/src/circuit_tools/cell_manager.rs @@ -93,13 +93,13 @@ impl Cell { impl Expr for Cell { fn expr(&self) -> Expression { - self.expression.as_ref().unwrap().clone() + self.expression.clone().unwrap() } } impl Expr for &Cell { fn expr(&self) -> Expression { - self.expression.as_ref().unwrap().clone() + self.expression.clone().unwrap() } } @@ -284,11 +284,14 @@ impl CellManager { permutable: bool, num_columns: usize, ) { + self.columns.reserve(num_columns); + self.configs.reserve(num_columns); + for _ in 0..num_columns { // Add a column of the specified type let config = CellConfig::new(cell_type, phase, permutable); let col = config.init_column(meta); - let mut cells = Vec::new(); + let mut cells = Vec::with_capacity(self.height_limit); for r in 0..self.height_limit { query_expression(meta, |meta| { cells.push(Cell::new(meta, col, self.offset + r)); @@ -394,13 +397,11 @@ impl CellManager { } pub(crate) fn get_typed_columns(&self, cell_type: C) -> Vec> { - let mut columns = Vec::new(); - for column in self.columns.iter() { - if column.cell_type == cell_type { - columns.push(column.clone()); - } - } - columns + self.columns + .iter() + .filter(|column| column.cell_type == cell_type) + .cloned() + .collect() } } diff --git a/zkevm-circuits/src/circuit_tools/constraint_builder.rs b/zkevm-circuits/src/circuit_tools/constraint_builder.rs index b0ebc4ddc9..62bb78bdb2 100644 --- a/zkevm-circuits/src/circuit_tools/constraint_builder.rs +++ b/zkevm-circuits/src/circuit_tools/constraint_builder.rs @@ -390,8 +390,8 @@ impl ConstraintBuilder { .collect(); // Align the length of values and table assert!(lookup.table.len() >= values.len()); - while values.len() < lookup.table.len() { - values.push(0.expr()); + if values.len() < lookup.table.len() { + values.resize(lookup.table.len(), 0.expr()); } meta.lookup_any( Box::leak(lookup.description.clone().into_boxed_str()), diff --git a/zkevm-circuits/src/circuit_tools/memory.rs b/zkevm-circuits/src/circuit_tools/memory.rs index 7f1fb3cb2c..873ec23acb 100644 --- a/zkevm-circuits/src/circuit_tools/memory.rs +++ b/zkevm-circuits/src/circuit_tools/memory.rs @@ -68,10 +68,10 @@ impl> Memory { } pub(crate) fn get_columns(&self) -> Vec> { - self.banks.values().fold(Vec::new(), |mut acc, bank| { - acc.extend(bank.columns().iter()); - acc - }) + self.banks + .values() + .flat_map(|bank| bank.columns()) + .collect() } pub(crate) fn build_constraints( @@ -152,7 +152,7 @@ impl RwBank { self.cur.expr() } pub(crate) fn prepend_key(&self, values: &[Expression]) -> Vec> { - [&[self.cur.expr() + 1.expr()], values].concat().to_vec() + [&[self.cur.expr() + 1.expr()], values].concat() } pub(crate) fn prepend_offset( @@ -160,7 +160,7 @@ impl RwBank { values: &[Expression], offset: Expression, ) -> Vec> { - [&[self.cur.expr() - offset], values].concat().to_vec() + [&[self.cur.expr() - offset], values].concat() } }