Skip to content

Commit 0e5d7d2

Browse files
committed
Use SmallVec within MoveData.
This reduces allocation counts significantly in a few benchmarks, reducing instruction counts by up to 2%.
1 parent de9666f commit 0e5d7d2

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/librustc_mir/dataflow/move_paths/builder.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ use rustc::ty::{self, TyCtxt};
1212
use rustc::mir::*;
1313
use rustc::mir::tcx::RvalueInitializationState;
1414
use rustc_data_structures::indexed_vec::{IndexVec};
15+
use smallvec::{SmallVec, smallvec};
1516

1617
use std::collections::hash_map::Entry;
1718
use std::mem;
1819

1920
use super::abs_domain::Lift;
20-
2121
use super::{LocationMap, MoveData, MovePath, MovePathLookup, MovePathIndex, MoveOut, MoveOutIndex};
2222
use super::{MoveError, InitIndex, Init, InitLocation, LookupResult, InitKind};
2323
use super::IllegalMoveOriginKind::*;
@@ -64,8 +64,8 @@ impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> {
6464
}
6565

6666
fn new_move_path(move_paths: &mut IndexVec<MovePathIndex, MovePath<'tcx>>,
67-
path_map: &mut IndexVec<MovePathIndex, Vec<MoveOutIndex>>,
68-
init_path_map: &mut IndexVec<MovePathIndex, Vec<InitIndex>>,
67+
path_map: &mut IndexVec<MovePathIndex, SmallVec<[MoveOutIndex; 4]>>,
68+
init_path_map: &mut IndexVec<MovePathIndex, SmallVec<[InitIndex; 4]>>,
6969
parent: Option<MovePathIndex>,
7070
place: Place<'tcx>)
7171
-> MovePathIndex
@@ -83,10 +83,10 @@ impl<'a, 'gcx, 'tcx> MoveDataBuilder<'a, 'gcx, 'tcx> {
8383
move_paths[move_path].next_sibling = next_sibling;
8484
}
8585

86-
let path_map_ent = path_map.push(vec![]);
86+
let path_map_ent = path_map.push(smallvec![]);
8787
assert_eq!(path_map_ent, move_path);
8888

89-
let init_path_map_ent = init_path_map.push(vec![]);
89+
let init_path_map_ent = init_path_map.push(smallvec![]);
9090
assert_eq!(init_path_map_ent, move_path);
9191

9292
move_path

src/librustc_mir/dataflow/move_paths/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc::ty::{self, TyCtxt};
1313
use rustc::mir::*;
1414
use rustc::util::nodemap::FxHashMap;
1515
use rustc_data_structures::indexed_vec::{IndexVec};
16+
use smallvec::SmallVec;
1617
use syntax_pos::{Span};
1718

1819
use std::fmt;
@@ -141,14 +142,14 @@ pub struct MoveData<'tcx> {
141142
/// of executing the code at `l`. (There can be multiple MoveOut's
142143
/// for a given `l` because each MoveOut is associated with one
143144
/// particular path being moved.)
144-
pub loc_map: LocationMap<Vec<MoveOutIndex>>,
145-
pub path_map: IndexVec<MovePathIndex, Vec<MoveOutIndex>>,
145+
pub loc_map: LocationMap<SmallVec<[MoveOutIndex; 4]>>,
146+
pub path_map: IndexVec<MovePathIndex, SmallVec<[MoveOutIndex; 4]>>,
146147
pub rev_lookup: MovePathLookup<'tcx>,
147148
pub inits: IndexVec<InitIndex, Init>,
148149
/// Each Location `l` is mapped to the Inits that are effects
149150
/// of executing the code at `l`.
150-
pub init_loc_map: LocationMap<Vec<InitIndex>>,
151-
pub init_path_map: IndexVec<MovePathIndex, Vec<InitIndex>>,
151+
pub init_loc_map: LocationMap<SmallVec<[InitIndex; 4]>>,
152+
pub init_path_map: IndexVec<MovePathIndex, SmallVec<[InitIndex; 4]>>,
152153
}
153154

154155
pub trait HasMoveData<'tcx> {

0 commit comments

Comments
 (0)