Skip to content

Commit

Permalink
Use fold to code golf
Browse files Browse the repository at this point in the history
  • Loading branch information
fitzgen committed Nov 7, 2023
1 parent e88d7e7 commit bfe8a95
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions cranelift/codegen/src/egraph/cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@ impl Cost {

impl std::iter::Sum<Cost> for Cost {
fn sum<I: Iterator<Item = Cost>>(iter: I) -> Self {
let mut c = Self::zero();
for x in iter {
c = c + x;
}
c
iter.fold(Self::zero(), |a, b| a + b)
}
}

Expand Down

0 comments on commit bfe8a95

Please sign in to comment.