Take config by reference to avoid clone

This commit is contained in:
wborgeaud 2021-10-18 11:11:48 +02:00
parent ff3f0891bc
commit 9503bb22f4
4 changed files with 8 additions and 8 deletions

View File

@ -108,7 +108,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
exponent_bits: impl IntoIterator<Item = impl Borrow<BoolTarget>>, exponent_bits: impl IntoIterator<Item = impl Borrow<BoolTarget>>,
) -> Target { ) -> Target {
let _false = self._false(); let _false = self._false();
let gate = ExponentiationGate::new_from_config(self.config.clone()); let gate = ExponentiationGate::new_from_config(&self.config);
let num_power_bits = gate.num_power_bits; let num_power_bits = gate.num_power_bits;
let mut exp_bits_vec: Vec<BoolTarget> = let mut exp_bits_vec: Vec<BoolTarget> =
exponent_bits.into_iter().map(|b| *b.borrow()).collect(); exponent_bits.into_iter().map(|b| *b.borrow()).collect();

View File

@ -81,7 +81,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
let (gate, gate_index, mut next_copy) = let (gate, gate_index, mut next_copy) =
match self.current_switch_gates[chunk_size - 1].clone() { match self.current_switch_gates[chunk_size - 1].clone() {
None => { None => {
let gate = SwitchGate::<F, D>::new_from_config(self.config.clone(), chunk_size); let gate = SwitchGate::<F, D>::new_from_config(&self.config, chunk_size);
let gate_index = self.add_gate(gate.clone(), vec![]); let gate_index = self.add_gate(gate.clone(), vec![]);
(gate, gate_index, 0) (gate, gate_index, 0)
} }

View File

@ -27,7 +27,7 @@ impl<F: RichField + Extendable<D>, const D: usize> ExponentiationGate<F, D> {
} }
} }
pub fn new_from_config(config: CircuitConfig) -> Self { pub fn new_from_config(config: &CircuitConfig) -> Self {
let num_power_bits = Self::max_power_bits(config.num_wires, config.num_routed_wires); let num_power_bits = Self::max_power_bits(config.num_wires, config.num_routed_wires);
Self::new(num_power_bits) Self::new(num_power_bits)
} }
@ -302,13 +302,13 @@ mod tests {
..CircuitConfig::large_config() ..CircuitConfig::large_config()
}; };
test_low_degree::<CrandallField, _, 4>(ExponentiationGate::new_from_config(config)); test_low_degree::<CrandallField, _, 4>(ExponentiationGate::new_from_config(&config));
} }
#[test] #[test]
fn eval_fns() -> Result<()> { fn eval_fns() -> Result<()> {
test_eval_fns::<CrandallField, _, 4>(ExponentiationGate::new_from_config( test_eval_fns::<CrandallField, _, 4>(ExponentiationGate::new_from_config(
CircuitConfig::large_config(), &CircuitConfig::large_config(),
)) ))
} }

View File

@ -31,7 +31,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SwitchGate<F, D> {
} }
} }
pub fn new_from_config(config: CircuitConfig, chunk_size: usize) -> Self { pub fn new_from_config(config: &CircuitConfig, chunk_size: usize) -> Self {
let num_copies = Self::max_num_copies(config.num_routed_wires, chunk_size); let num_copies = Self::max_num_copies(config.num_routed_wires, chunk_size);
Self::new(num_copies, chunk_size) Self::new(num_copies, chunk_size)
} }
@ -352,7 +352,7 @@ mod tests {
#[test] #[test]
fn low_degree() { fn low_degree() {
test_low_degree::<CrandallField, _, 4>(SwitchGate::<_, 4>::new_from_config( test_low_degree::<CrandallField, _, 4>(SwitchGate::<_, 4>::new_from_config(
CircuitConfig::large_config(), &CircuitConfig::large_config(),
3, 3,
)); ));
} }
@ -360,7 +360,7 @@ mod tests {
#[test] #[test]
fn eval_fns() -> Result<()> { fn eval_fns() -> Result<()> {
test_eval_fns::<CrandallField, _, 4>(SwitchGate::<_, 4>::new_from_config( test_eval_fns::<CrandallField, _, 4>(SwitchGate::<_, 4>::new_from_config(
CircuitConfig::large_config(), &CircuitConfig::large_config(),
3, 3,
)) ))
} }