1
Fork 0

Use SmallVec within MoveData.

This reduces allocation counts significantly in a few benchmarks,
reducing instruction counts by up to 2%.
This commit is contained in:
Nicholas Nethercote 2018-11-01 15:34:36 +11:00
parent de9666f123
commit 0e5d7d2322
2 changed files with 10 additions and 9 deletions

View file

@ -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<MovePathIndex, MovePath<'tcx>>,
path_map: &mut IndexVec<MovePathIndex, Vec<MoveOutIndex>>,
init_path_map: &mut IndexVec<MovePathIndex, Vec<InitIndex>>,
path_map: &mut IndexVec<MovePathIndex, SmallVec<[MoveOutIndex; 4]>>,
init_path_map: &mut IndexVec<MovePathIndex, SmallVec<[InitIndex; 4]>>,
parent: Option<MovePathIndex>,
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

View file

@ -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<Vec<MoveOutIndex>>,
pub path_map: IndexVec<MovePathIndex, Vec<MoveOutIndex>>,
pub loc_map: LocationMap<SmallVec<[MoveOutIndex; 4]>>,
pub path_map: IndexVec<MovePathIndex, SmallVec<[MoveOutIndex; 4]>>,
pub rev_lookup: MovePathLookup<'tcx>,
pub inits: IndexVec<InitIndex, Init>,
/// Each Location `l` is mapped to the Inits that are effects
/// of executing the code at `l`.
pub init_loc_map: LocationMap<Vec<InitIndex>>,
pub init_path_map: IndexVec<MovePathIndex, Vec<InitIndex>>,
pub init_loc_map: LocationMap<SmallVec<[InitIndex; 4]>>,
pub init_path_map: IndexVec<MovePathIndex, SmallVec<[InitIndex; 4]>>,
}
pub trait HasMoveData<'tcx> {