From 0e5d7d2322db2a5db82161dc1d57158acad7b2d9 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 1 Nov 2018 15:34:36 +1100 Subject: [PATCH] Use `SmallVec` within `MoveData`. This reduces allocation counts significantly in a few benchmarks, reducing instruction counts by up to 2%. --- src/librustc_mir/dataflow/move_paths/builder.rs | 10 +++++----- src/librustc_mir/dataflow/move_paths/mod.rs | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/librustc_mir/dataflow/move_paths/builder.rs b/src/librustc_mir/dataflow/move_paths/builder.rs index 08696dc098e00..b46489a162b85 100644 --- a/src/librustc_mir/dataflow/move_paths/builder.rs +++ b/src/librustc_mir/dataflow/move_paths/builder.rs @@ -12,12 +12,12 @@ use rustc::ty::{self, TyCtxt}; use rustc::mir::*; use rustc::mir::tcx::RvalueInitializationState; use rustc_data_structures::indexed_vec::{IndexVec}; +use smallvec::{SmallVec, smallvec}; use std::collections::hash_map::Entry; use std::mem; use super::abs_domain::Lift; - use super::{LocationMap, MoveData, MovePath, MovePathLookup, MovePathIndex, MoveOut, MoveOutIndex}; use super::{MoveError, InitIndex, Init, InitLocation, LookupResult, InitKind}; use super::IllegalMoveOriginKind::*; @@ -64,8 +64,8 @@ impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> { } fn new_move_path(move_paths: &mut IndexVec>, - path_map: &mut IndexVec>, - init_path_map: &mut IndexVec>, + path_map: &mut IndexVec>, + init_path_map: &mut IndexVec>, parent: Option, place: Place<'tcx>) -> MovePathIndex @@ -83,10 +83,10 @@ impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> { move_paths[move_path].next_sibling = next_sibling; } - let path_map_ent = path_map.push(vec![]); + let path_map_ent = path_map.push(smallvec![]); assert_eq!(path_map_ent, move_path); - let init_path_map_ent = init_path_map.push(vec![]); + let init_path_map_ent = init_path_map.push(smallvec![]); assert_eq!(init_path_map_ent, move_path); move_path diff --git a/src/librustc_mir/dataflow/move_paths/mod.rs b/src/librustc_mir/dataflow/move_paths/mod.rs index 58a2b9361032e..2a026b8f52c2a 100644 --- a/src/librustc_mir/dataflow/move_paths/mod.rs +++ b/src/librustc_mir/dataflow/move_paths/mod.rs @@ -13,6 +13,7 @@ use rustc::ty::{self, TyCtxt}; use rustc::mir::*; use rustc::util::nodemap::FxHashMap; use rustc_data_structures::indexed_vec::{IndexVec}; +use smallvec::SmallVec; use syntax_pos::{Span}; use std::fmt; @@ -141,14 +142,14 @@ pub struct MoveData<'tcx> { /// of executing the code at `l`. (There can be multiple MoveOut's /// for a given `l` because each MoveOut is associated with one /// particular path being moved.) - pub loc_map: LocationMap>, - pub path_map: IndexVec>, + pub loc_map: LocationMap>, + pub path_map: IndexVec>, pub rev_lookup: MovePathLookup<'tcx>, pub inits: IndexVec, /// Each Location `l` is mapped to the Inits that are effects /// of executing the code at `l`. - pub init_loc_map: LocationMap>, - pub init_path_map: IndexVec>, + pub init_loc_map: LocationMap>, + pub init_path_map: IndexVec>, } pub trait HasMoveData<'tcx> {