Skip to content

Commit

Permalink
Remove unnecessary clones
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Nov 14, 2023
1 parent a0713c0 commit 64b488d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 64 deletions.
39 changes: 12 additions & 27 deletions crates/fj-core/src/operations/replace/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl ReplaceCurve for Handle<Cycle> {

let mut half_edges = Vec::new();
for half_edge in self.half_edges() {
let half_edge = half_edge.clone().replace_curve(
let half_edge = half_edge.replace_curve(
original,
replacement.clone(),
services,
Expand Down Expand Up @@ -84,7 +84,7 @@ impl ReplaceCurve for Handle<Region> {
) -> ReplaceOutput<Self::BareObject> {
let mut replacement_happened = false;

let exterior = self.exterior().clone().replace_curve(
let exterior = self.exterior().replace_curve(
original,
replacement.clone(),
services,
Expand All @@ -93,11 +93,8 @@ impl ReplaceCurve for Handle<Region> {

let mut interiors = Vec::new();
for cycle in self.interiors() {
let cycle = cycle.clone().replace_curve(
original,
replacement.clone(),
services,
);
let cycle =
cycle.replace_curve(original, replacement.clone(), services);
replacement_happened |= cycle.was_updated();
interiors.push(cycle.into_inner(services));
}
Expand Down Expand Up @@ -127,11 +124,8 @@ impl ReplaceCurve for Handle<Sketch> {

let mut regions = Vec::new();
for region in self.regions() {
let region = region.clone().replace_curve(
original,
replacement.clone(),
services,
);
let region =
region.replace_curve(original, replacement.clone(), services);
replacement_happened |= region.was_updated();
regions.push(region.into_inner(services));
}
Expand All @@ -153,11 +147,8 @@ impl ReplaceCurve for Handle<Face> {
replacement: Handle<Curve>,
services: &mut Services,
) -> ReplaceOutput<Self::BareObject> {
let region = self.region().clone().replace_curve(
original,
replacement,
services,
);
let region =
self.region().replace_curve(original, replacement, services);

if region.was_updated() {
ReplaceOutput::Updated(Face::new(
Expand All @@ -183,11 +174,8 @@ impl ReplaceCurve for Handle<Shell> {

let mut faces = Vec::new();
for face in self.faces() {
let face = face.clone().replace_curve(
original,
replacement.clone(),
services,
);
let face =
face.replace_curve(original, replacement.clone(), services);
replacement_happened |= face.was_updated();
faces.push(face.into_inner(services));
}
Expand All @@ -213,11 +201,8 @@ impl ReplaceCurve for Handle<Solid> {

let mut shells = Vec::new();
for shell in self.shells() {
let shell = shell.clone().replace_curve(
original,
replacement.clone(),
services,
);
let shell =
shell.replace_curve(original, replacement.clone(), services);
replacement_happened |= shell.was_updated();
shells.push(shell.into_inner(services));
}
Expand Down
18 changes: 8 additions & 10 deletions crates/fj-core/src/operations/replace/half_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl ReplaceHalfEdge for Handle<Region> {
) -> ReplaceOutput<Self::BareObject> {
let mut replacement_happened = false;

let exterior = self.exterior().clone().replace_half_edge(
let exterior = self.exterior().replace_half_edge(
original,
replacements.clone(),
services,
Expand All @@ -64,7 +64,7 @@ impl ReplaceHalfEdge for Handle<Region> {

let mut interiors = Vec::new();
for cycle in self.interiors() {
let cycle = cycle.clone().replace_half_edge(
let cycle = cycle.replace_half_edge(
original,
replacements.clone(),
services,
Expand Down Expand Up @@ -98,7 +98,7 @@ impl ReplaceHalfEdge for Handle<Sketch> {

let mut regions = Vec::new();
for region in self.regions() {
let region = region.clone().replace_half_edge(
let region = region.replace_half_edge(
original,
replacements.clone(),
services,
Expand All @@ -124,11 +124,9 @@ impl ReplaceHalfEdge for Handle<Face> {
replacements: [Handle<HalfEdge>; N],
services: &mut Services,
) -> ReplaceOutput<Self::BareObject> {
let region = self.region().clone().replace_half_edge(
original,
replacements,
services,
);
let region =
self.region()
.replace_half_edge(original, replacements, services);

if region.was_updated() {
ReplaceOutput::Updated(Face::new(
Expand All @@ -154,7 +152,7 @@ impl ReplaceHalfEdge for Handle<Shell> {

let mut faces = Vec::new();
for face in self.faces() {
let face = face.clone().replace_half_edge(
let face = face.replace_half_edge(
original,
replacements.clone(),
services,
Expand Down Expand Up @@ -184,7 +182,7 @@ impl ReplaceHalfEdge for Handle<Solid> {

let mut shells = Vec::new();
for shell in self.shells() {
let shell = shell.clone().replace_half_edge(
let shell = shell.replace_half_edge(
original,
replacements.clone(),
services,
Expand Down
40 changes: 13 additions & 27 deletions crates/fj-core/src/operations/replace/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl ReplaceVertex for Handle<Cycle> {

let mut half_edges = Vec::new();
for half_edge in self.half_edges() {
let half_edge = half_edge.clone().replace_vertex(
let half_edge = half_edge.replace_vertex(
original,
replacement.clone(),
services,
Expand Down Expand Up @@ -84,7 +84,7 @@ impl ReplaceVertex for Handle<Region> {
) -> ReplaceOutput<Self::BareObject> {
let mut replacement_happened = false;

let exterior = self.exterior().clone().replace_vertex(
let exterior = self.exterior().replace_vertex(
original,
replacement.clone(),
services,
Expand All @@ -93,11 +93,8 @@ impl ReplaceVertex for Handle<Region> {

let mut interiors = Vec::new();
for cycle in self.interiors() {
let cycle = cycle.clone().replace_vertex(
original,
replacement.clone(),
services,
);
let cycle =
cycle.replace_vertex(original, replacement.clone(), services);
replacement_happened |= cycle.was_updated();
interiors.push(cycle.into_inner(services));
}
Expand Down Expand Up @@ -127,11 +124,8 @@ impl ReplaceVertex for Handle<Sketch> {

let mut regions = Vec::new();
for region in self.regions() {
let region = region.clone().replace_vertex(
original,
replacement.clone(),
services,
);
let region =
region.replace_vertex(original, replacement.clone(), services);
replacement_happened |= region.was_updated();
regions.push(region.into_inner(services));
}
Expand All @@ -153,11 +147,9 @@ impl ReplaceVertex for Handle<Face> {
replacement: Handle<Vertex>,
services: &mut Services,
) -> ReplaceOutput<Self::BareObject> {
let region = self.region().clone().replace_vertex(
original,
replacement,
services,
);
let region =
self.region()
.replace_vertex(original, replacement, services);

if region.was_updated() {
ReplaceOutput::Updated(Face::new(
Expand All @@ -183,11 +175,8 @@ impl ReplaceVertex for Handle<Shell> {

let mut faces = Vec::new();
for face in self.faces() {
let face = face.clone().replace_vertex(
original,
replacement.clone(),
services,
);
let face =
face.replace_vertex(original, replacement.clone(), services);
replacement_happened |= face.was_updated();
faces.push(face.into_inner(services));
}
Expand All @@ -213,11 +202,8 @@ impl ReplaceVertex for Handle<Solid> {

let mut shells = Vec::new();
for shell in self.shells() {
let shell = shell.clone().replace_vertex(
original,
replacement.clone(),
services,
);
let shell =
shell.replace_vertex(original, replacement.clone(), services);
replacement_happened |= shell.was_updated();
shells.push(shell.into_inner(services));
}
Expand Down

0 comments on commit 64b488d

Please sign in to comment.