diff options
| author | Nicholas Nethercote <nnethercote@mozilla.com> | 2019-10-16 17:22:35 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2019-10-16 18:47:20 +1100 |
| commit | c4deea212d19b19fa11fb4e29dd5c7f1359543a5 (patch) | |
| tree | 8c38a77a200be90bcbd33102f1df71a219fb09da | |
| parent | 237d54ff6c4fb3577e02d4c5af02813c11b63d01 (diff) | |
| download | rust-c4deea212d19b19fa11fb4e29dd5c7f1359543a5.tar.gz rust-c4deea212d19b19fa11fb4e29dd5c7f1359543a5.zip | |
Avoid unnecessary arena allocations in `expand_pattern()`.
`expand_pattern()` has two callsites. One of them needs arena allocation, but the other does not. This commit moves the arena allocation out of the function. This avoids the allocation of many 4 KiB page arena chunks that only hold a single small allocation. It reduces the number of bytes allocated by up to 2% for various benchmarks, albeit without only a very small improvement in runtime.
| -rw-r--r-- | src/librustc_mir/hair/pattern/_match.rs | 4 | ||||
| -rw-r--r-- | src/librustc_mir/hair/pattern/check_match.rs | 6 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index 3ea58052877..bcbb14137c7 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -188,8 +188,8 @@ use std::ops::RangeInclusive; use std::u128; use std::convert::TryInto; -pub fn expand_pattern<'a, 'tcx>(cx: &MatchCheckCtxt<'a, 'tcx>, pat: Pat<'tcx>) -> &'a Pat<'tcx> { - cx.pattern_arena.alloc(LiteralExpander { tcx: cx.tcx }.fold_pattern(&pat)) +pub fn expand_pattern<'a, 'tcx>(cx: &MatchCheckCtxt<'a, 'tcx>, pat: Pat<'tcx>) -> Pat<'tcx> { + LiteralExpander { tcx: cx.tcx }.fold_pattern(&pat) } struct LiteralExpander<'tcx> { diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 9bed4fb66ea..27ad56fd29b 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -153,7 +153,8 @@ impl<'tcx> MatchVisitor<'_, 'tcx> { self.tables ); patcx.include_lint_checks(); - let pattern = expand_pattern(cx, patcx.lower_pattern(&pat)); + let pattern = + cx.pattern_arena.alloc(expand_pattern(cx, patcx.lower_pattern(&pat))) as &_; if !patcx.errors.is_empty() { patcx.report_inlining_errors(pat.span); have_errors = true; @@ -252,8 +253,9 @@ impl<'tcx> MatchVisitor<'_, 'tcx> { patcx.include_lint_checks(); let pattern = patcx.lower_pattern(pat); let pattern_ty = pattern.ty; + let pattern = expand_pattern(cx, pattern); let pats: Matrix<'_, '_> = vec![smallvec![ - expand_pattern(cx, pattern) + &pattern ]].into_iter().collect(); let witnesses = match check_not_useful(cx, pattern_ty, &pats) { |
