Skip to content

Commit e182bff

Browse files
authored
Rollup merge of rust-lang#55755 - ljedrz:a_few_indexvec_tweaks, r=varkor
Improve creation of 3 IndexVecs - preallocate when the minimal size is known - use `from_elem_n` instead of `new`+`resize`
2 parents b04a197 + e3390d8 commit e182bff

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/librustc/ty/query/on_disk_cache.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,7 @@ impl<'sess> OnDiskCache<'sess> {
450450
.map(|&(cnum, ..)| cnum)
451451
.max()
452452
.unwrap_or(0) + 1;
453-
let mut map = IndexVec::new();
454-
map.resize(map_size as usize, None);
453+
let mut map = IndexVec::from_elem_n(None, map_size as usize);
455454

456455
for &(prev_cnum, ref crate_name, crate_disambiguator) in prev_cnums {
457456
let key = (crate_name.clone(), crate_disambiguator);

src/librustc_mir/shim.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ fn build_drop_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
196196
let source_info = SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE };
197197

198198
let return_block = BasicBlock::new(1);
199-
let mut blocks = IndexVec::new();
199+
let mut blocks = IndexVec::with_capacity(2);
200200
let block = |blocks: &mut IndexVec<_, _>, kind| {
201201
blocks.push(BasicBlockData {
202202
statements: vec![],
@@ -768,7 +768,8 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
768768
}));
769769
}
770770

771-
let mut blocks = IndexVec::new();
771+
let n_blocks = if let Adjustment::RefMut = rcvr_adjustment { 5 } else { 2 };
772+
let mut blocks = IndexVec::with_capacity(n_blocks);
772773
let block = |blocks: &mut IndexVec<_, _>, statements, kind, is_cleanup| {
773774
blocks.push(BasicBlockData {
774775
statements,

0 commit comments

Comments
 (0)