From 130e55665f8c9f078dec67a3e92467853f400250 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 27 Aug 2018 16:40:42 +1000 Subject: [PATCH] Avoid calling `unroll_place()` in a common case. This reduces the execution time for `ucd-check` by 25%. --- src/librustc_mir/borrow_check/places_conflict.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/librustc_mir/borrow_check/places_conflict.rs b/src/librustc_mir/borrow_check/places_conflict.rs index f7917356909..3f055283e0c 100644 --- a/src/librustc_mir/borrow_check/places_conflict.rs +++ b/src/librustc_mir/borrow_check/places_conflict.rs @@ -29,6 +29,14 @@ pub(super) fn places_conflict<'gcx, 'tcx>( borrow_place, access_place, access ); + // This Local/Local case is handled by the more general code below, but + // it's so common that it's a speed win to check for it first. + if let Place::Local(l1) = borrow_place { + if let Place::Local(l2) = access_place { + return l1 == l2; + } + } + unroll_place(borrow_place, None, |borrow_components| { unroll_place(access_place, None, |access_components| { place_components_conflict(tcx, mir, borrow_components, access_components, access)