refactor(topola): get rid of unnecessary clones and lookups

This commit is contained in:
Alain Emilia Anna Zscheile 2024-12-06 20:13:04 +01:00 committed by mikolaj
parent 5425ac2d3a
commit 27a4b61c4d
3 changed files with 14 additions and 17 deletions

View File

@ -82,9 +82,9 @@ impl<M: AccessMesadata> Board<M> {
) -> FixedDotIndex { ) -> FixedDotIndex {
let dot = self.layout.add_fixed_dot_infringably(recorder, weight); let dot = self.layout.add_fixed_dot_infringably(recorder, weight);
if let Some(ref pin) = maybe_pin { if let Some(pin) = maybe_pin {
self.node_to_pinname self.node_to_pinname
.insert(GenericNode::Primitive(dot.into()), pin.clone()); .insert(GenericNode::Primitive(dot.into()), pin);
} }
dot dot
@ -128,7 +128,7 @@ impl<M: AccessMesadata> Board<M> {
if let Some(pin) = maybe_pin { if let Some(pin) = maybe_pin {
self.node_to_pinname self.node_to_pinname
.insert(GenericNode::Primitive(seg.into()), pin.to_string()); .insert(GenericNode::Primitive(seg.into()), pin);
} }
seg seg
@ -170,7 +170,7 @@ impl<M: AccessMesadata> Board<M> {
if let Some(pin) = maybe_pin { if let Some(pin) = maybe_pin {
self.node_to_pinname self.node_to_pinname
.insert(GenericNode::Compound(poly.into()), pin.to_string()); .insert(GenericNode::Compound(poly.into()), pin);
} }
poly poly
@ -184,18 +184,19 @@ impl<M: AccessMesadata> Board<M> {
recorder: &mut LayoutEdit, recorder: &mut LayoutEdit,
poly: GenericIndex<PolyWeight>, poly: GenericIndex<PolyWeight>,
) -> FixedDotIndex { ) -> FixedDotIndex {
if let Some(apex) = self.layout.poly(poly).maybe_apex() { let resolved_poly = self.layout.poly(poly);
if let Some(apex) = resolved_poly.maybe_apex() {
apex apex
} else { } else {
self.add_poly_fixed_dot_infringably( self.add_poly_fixed_dot_infringably(
recorder, recorder,
FixedDotWeight { FixedDotWeight {
circle: Circle { circle: Circle {
pos: self.layout.poly(poly).shape().center(), pos: resolved_poly.shape().center(),
r: 100.0, r: 100.0,
}, },
layer: self.layout.poly(poly).layer(), layer: resolved_poly.layer(),
maybe_net: self.layout.poly(poly).maybe_net(), maybe_net: resolved_poly.maybe_net(),
}, },
poly, poly,
) )
@ -240,14 +241,10 @@ impl<M: AccessMesadata> Board<M> {
pub fn band_between_pins(&self, pinname1: &str, pinname2: &str) -> Option<BandUid> { pub fn band_between_pins(&self, pinname1: &str, pinname2: &str) -> Option<BandUid> {
if let Some(band) = self if let Some(band) = self
.band_bandname .band_bandname
// note: it doesn't matter in what order pinnames are given, the constructor sorts them
.get_by_right(&BandName::new(pinname1.to_string(), pinname2.to_string())) .get_by_right(&BandName::new(pinname1.to_string(), pinname2.to_string()))
{ {
Some(*band) Some(*band)
} else if let Some(band) = self
.band_bandname
.get_by_right(&BandName::new(pinname2.to_string(), pinname1.to_string()))
{
Some(*band)
} else { } else {
None None
} }

View File

@ -35,7 +35,7 @@ impl RouteStepper {
to: FixedDotIndex, to: FixedDotIndex,
width: f64, width: f64,
) -> Result<Self, NavmeshError> { ) -> Result<Self, NavmeshError> {
let navmesh = Navmesh::new(router.layout(), from, to, router.options().clone())?; let navmesh = Navmesh::new(router.layout(), from, to, *router.options())?;
Ok(Self::new_from_navmesh(router, recorder, navmesh, width)) Ok(Self::new_from_navmesh(router, recorder, navmesh, width))
} }

View File

@ -448,7 +448,7 @@ impl SpecctraDesign {
layer, layer,
maybe_net, maybe_net,
}, },
maybe_pin.clone(), maybe_pin,
); );
} }
@ -468,7 +468,7 @@ impl SpecctraDesign {
let poly = board.add_poly( let poly = board.add_poly(
recorder, recorder,
SolidPolyWeight { layer, maybe_net }.into(), SolidPolyWeight { layer, maybe_net }.into(),
maybe_pin.clone(), maybe_pin,
); );
// Corners. // Corners.
@ -646,7 +646,7 @@ impl SpecctraDesign {
let poly = board.add_poly( let poly = board.add_poly(
recorder, recorder,
SolidPolyWeight { layer, maybe_net }.into(), SolidPolyWeight { layer, maybe_net }.into(),
maybe_pin.clone(), maybe_pin,
); );
// add the first coordinate in the wire path as a dot and save its index // add the first coordinate in the wire path as a dot and save its index