diff --git a/crates/noirc_evaluator/src/ssa/acir_gen/mod.rs b/crates/noirc_evaluator/src/ssa/acir_gen/mod.rs index 331c56f59d7..f1e71922b0b 100644 --- a/crates/noirc_evaluator/src/ssa/acir_gen/mod.rs +++ b/crates/noirc_evaluator/src/ssa/acir_gen/mod.rs @@ -589,19 +589,17 @@ impl Context { let result_array_id = result_id.to_usize() as u32; let result_block_id = BlockId(result_array_id); - // Initialize the new array with zero values - self.initialize_array(result_block_id, len, None)?; - - // Copy the values from the old array into the newly created zeroed array - for i in 0..len { + // Initialize the new array with the values from the old array + let init_values = try_vecmap(0..len, |i| { let index = AcirValue::Var( self.acir_context.add_constant(FieldElement::from(i as u128)), AcirType::NumericType(NumericType::NativeField), ); let var = index.into_var()?; let read = self.acir_context.read_from_memory(block_id, &var)?; - self.acir_context.write_to_memory(result_block_id, &var, &read)?; - } + Ok(AcirValue::Var(read, AcirType::NumericType(NumericType::NativeField))) + })?; + self.initialize_array(result_block_id, len, Some(&init_values))?; // Write the new value into the new array at the specified index let index_var = self.convert_value(index, dfg).into_var()?;