Rollup merge of #65463 - nnethercote:rm-arena-allocation-from-expand_pattern, r=varkor

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.
This commit is contained in:
Yuki Okushi 2019-10-21 03:10:55 +09:00 committed by GitHub
commit cc42adf3a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View file

@ -189,8 +189,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> {

View file

@ -154,7 +154,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;
@ -253,8 +254,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, pat.hir_id) {