Skip to content

Commit ba0bb02

Browse files
committed
Return a SmallVec from place_elements.
These vectors are always small, so this avoids lots of allocations.
1 parent 8c7433a commit ba0bb02

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/librustc_mir/borrow_check/path_utils.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc::mir::{BasicBlock, Location, Mir, Place};
2121
use rustc::mir::{Projection, ProjectionElem, BorrowKind};
2222
use rustc::ty::{self, TyCtxt};
2323
use rustc_data_structures::control_flow_graph::dominators::Dominators;
24+
use rustc_data_structures::small_vec::SmallVec;
2425
use std::iter;
2526

2627
pub(super) fn allow_two_phase_borrow<'a, 'tcx, 'gcx: 'tcx>(
@@ -259,8 +260,8 @@ pub(super) fn places_conflict<'a, 'gcx: 'tcx, 'tcx>(
259260

260261
/// Return all the prefixes of `place` in reverse order, including
261262
/// downcasts.
262-
fn place_elements<'a, 'tcx>(place: &'a Place<'tcx>) -> Vec<&'a Place<'tcx>> {
263-
let mut result = vec![];
263+
fn place_elements<'a, 'tcx>(place: &'a Place<'tcx>) -> SmallVec<[&'a Place<'tcx>; 8]> {
264+
let mut result = SmallVec::new();
264265
let mut place = place;
265266
loop {
266267
result.push(place);

0 commit comments

Comments
 (0)