Skip to content

Commit

Permalink
Return a SmallVec from place_elements.
Browse files Browse the repository at this point in the history
These vectors are always small, so this avoids lots of allocations.
  • Loading branch information
nnethercote committed Jun 18, 2018
1 parent 8c7433a commit ba0bb02
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/librustc_mir/borrow_check/path_utils.rs
Expand Up @@ -21,6 +21,7 @@ use rustc::mir::{BasicBlock, Location, Mir, Place};
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>(
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ba0bb02

Please sign in to comment.