Skip to content

Commit

Permalink
Replace flat_map() with filter_map() in is_useful_specialized().
Browse files Browse the repository at this point in the history
`filter_map()` is less general, but more efficient, and has the same
effect in this case.

This commit reduces the instruction count for
`unicode_normalization-check-clean` by about 2%.
  • Loading branch information
nnethercote committed Oct 4, 2019
1 parent 5515a97 commit 2a3a544
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/librustc_mir/hair/pattern/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1355,9 +1355,11 @@ fn is_useful_specialized<'p, 'a, 'tcx>(
}
}).collect();
let wild_patterns: Vec<_> = wild_patterns_owned.iter().collect();
let matrix = Matrix(m.iter().flat_map(|r| {
specialize(cx, &r, &ctor, &wild_patterns)
}).collect());
let matrix = Matrix(
m.iter()
.filter_map(|r| specialize(cx, &r, &ctor, &wild_patterns))
.collect()
);
match specialize(cx, v, &ctor, &wild_patterns) {
Some(v) => match is_useful(cx, &matrix, &v, witness) {
UsefulWithWitness(witnesses) => UsefulWithWitness(
Expand Down

0 comments on commit 2a3a544

Please sign in to comment.