From 5c377e805bfa75d1c5a24744a081ca81d76677af Mon Sep 17 00:00:00 2001 From: Alain Emilia Anna Zscheile Date: Sat, 5 Oct 2024 00:34:21 +0200 Subject: [PATCH] general refactor: omit unnecessary clones --- src/autorouter/measure_length.rs | 6 +----- src/autorouter/remove_bands.rs | 6 +----- src/autorouter/selection.rs | 4 ++-- src/board/board.rs | 20 ++++++++++---------- 4 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/autorouter/measure_length.rs b/src/autorouter/measure_length.rs index 3bd863c..317c866 100644 --- a/src/autorouter/measure_length.rs +++ b/src/autorouter/measure_length.rs @@ -39,11 +39,7 @@ impl MeasureLengthExecutionStepper { let mut length = 0.0; for selector in self.selection.selectors() { - let band = autorouter - .board - .bandname_band(selector.band.clone()) - .unwrap() - .0; + let band = autorouter.board.bandname_band(&selector.band).unwrap().0; length += band.ref_(autorouter.board.layout().drawing()).length(); } diff --git a/src/autorouter/remove_bands.rs b/src/autorouter/remove_bands.rs index b144c5b..ece9b46 100644 --- a/src/autorouter/remove_bands.rs +++ b/src/autorouter/remove_bands.rs @@ -35,11 +35,7 @@ impl RemoveBandsExecutionStepper { self.done = true; for selector in self.selection.selectors() { - let band = autorouter - .board - .bandname_band(selector.band.clone()) - .unwrap() - .0; + let band = autorouter.board.bandname_band(&selector.band).unwrap().0; autorouter.board.layout_mut().remove_band(band); } Ok(()) diff --git a/src/autorouter/selection.rs b/src/autorouter/selection.rs index b060328..daa6118 100644 --- a/src/autorouter/selection.rs +++ b/src/autorouter/selection.rs @@ -63,7 +63,7 @@ impl PinSelection { }; if let (Some(pinname), Some(layername)) = ( - board.node_pinname(node), + board.node_pinname(&node), board.layout().rules().layer_layername(layer), ) { Some(PinSelector { @@ -127,7 +127,7 @@ impl BandSelection { Some(BandSelector { band: board - .band_bandname(board.layout().drawing().collect().loose_band_uid(loose))? + .band_bandname(&board.layout().drawing().collect().loose_band_uid(loose))? .clone(), }) } diff --git a/src/board/board.rs b/src/board/board.rs index 6799b76..b12597d 100644 --- a/src/board/board.rs +++ b/src/board/board.rs @@ -86,7 +86,7 @@ impl Board { ) -> FixedDotIndex { let dot = self.layout.add_poly_fixed_dot_infringably(weight, poly); - if let Some(pin) = self.node_pinname(GenericNode::Compound(poly.into())) { + if let Some(pin) = self.node_pinname(&GenericNode::Compound(poly.into())) { self.node_to_pinname .insert(GenericNode::Primitive(dot.into()), pin.to_string()); } @@ -128,7 +128,7 @@ impl Board { .layout .add_poly_fixed_seg_infringably(from, to, weight, poly); - if let Some(pin) = self.node_pinname(GenericNode::Compound(poly.into())) { + if let Some(pin) = self.node_pinname(&GenericNode::Compound(poly.into())) { self.node_to_pinname .insert(GenericNode::Primitive(seg.into()), pin.to_string()); } @@ -176,18 +176,18 @@ impl Board { } /// Returns the pin name associated with a given node. - pub fn node_pinname(&self, node: NodeIndex) -> Option<&String> { - self.node_to_pinname.get(&node) + pub fn node_pinname(&self, node: &NodeIndex) -> Option<&String> { + self.node_to_pinname.get(node) } /// Returns the band name associated with a given band. - pub fn band_bandname(&self, band: BandUid) -> Option<&BandName> { - self.band_bandname.get_by_left(&band) + pub fn band_bandname(&self, band: &BandUid) -> Option<&BandName> { + self.band_bandname.get_by_left(band) } /// Returns the unique id associated with a given band name. - pub fn bandname_band(&self, bandname: BandName) -> Option<&BandUid> { - self.band_bandname.get_by_right(&bandname) + pub fn bandname_band(&self, bandname: &BandName) -> Option<&BandUid> { + self.band_bandname.get_by_right(bandname) } /// Creates band between the two nodes @@ -198,11 +198,11 @@ impl Board { band: BandUid, ) { let source_pinname = self - .node_pinname(GenericNode::Primitive(source.into())) + .node_pinname(&GenericNode::Primitive(source.into())) .unwrap() .to_string(); let target_pinname = self - .node_pinname(GenericNode::Primitive(target.into())) + .node_pinname(&GenericNode::Primitive(target.into())) .unwrap() .to_string(); self.band_bandname