]> git.lizzy.rs Git - rust.git/commitdiff
Return a `SmallVec` from `place_elements`.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 18 Jun 2018 06:32:28 +0000 (16:32 +1000)
committerNicholas Nethercote <nnethercote@mozilla.com>
Mon, 18 Jun 2018 23:37:31 +0000 (09:37 +1000)
These vectors are always small, so this avoids lots of allocations.

src/librustc_mir/borrow_check/path_utils.rs

index 4871d427d0767bc7bc6ebd2caddbb4ce8210f703..b692ffbb250c70b0586c017e3cc73bff5dced6c7 100644 (file)
@@ -21,6 +21,7 @@
 use rustc::mir::{Projection, ProjectionElem, BorrowKind};
 use rustc::ty::{self, TyCtxt};
 use rustc_data_structures::control_flow_graph::dominators::Dominators;
+use rustc_data_structures::small_vec::SmallVec;
 use std::iter;
 
 pub(super) fn allow_two_phase_borrow<'a, 'tcx, 'gcx: 'tcx>(
@@ -259,8 +260,8 @@ pub(super) fn places_conflict<'a, 'gcx: 'tcx, 'tcx>(
 
 /// Return all the prefixes of `place` in reverse order, including
 /// downcasts.
-fn place_elements<'a, 'tcx>(place: &'a Place<'tcx>) -> Vec<&'a Place<'tcx>> {
-    let mut result = vec![];
+fn place_elements<'a, 'tcx>(place: &'a Place<'tcx>) -> SmallVec<[&'a Place<'tcx>; 8]> {
+    let mut result = SmallVec::new();
     let mut place = place;
     loop {
         result.push(place);