Skip to content

Commit e62ce98

Browse files
committed
nll: improve allocations
1 parent 1dceadd commit e62ce98

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/librustc_mir/borrow_check/nll/constraint_generation.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx
141141
if let Some(all_facts) = self.all_facts {
142142
if let Place::Local(temp) = place {
143143
if let Some(borrow_indices) = self.borrow_set.local_map.get(temp) {
144+
all_facts.killed.reserve(borrow_indices.len());
144145
for &borrow_index in borrow_indices {
145146
let location_index = self.location_table.mid_index(location);
146147
all_facts.killed.push((borrow_index, location_index));
@@ -164,7 +165,9 @@ impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx
164165
self.location_table.mid_index(location),
165166
));
166167

167-
for successor_block in terminator.successors() {
168+
let successor_blocks = terminator.successors();
169+
all_facts.cfg_edge.reserve(successor_blocks.size_hint().0);
170+
for successor_block in successor_blocks {
168171
all_facts.cfg_edge.push((
169172
self.location_table.mid_index(location),
170173
self.location_table

src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
279279
pending_locations.push(target.start_location());
280280
},
281281
TerminatorKind::SwitchInt { ref targets, .. } => {
282-
for target in targets {
283-
pending_locations.push(target.start_location());
284-
}
282+
pending_locations.extend(
283+
targets.into_iter().map(|target| target.start_location()));
285284
},
286285
TerminatorKind::Drop { target, unwind, .. } |
287286
TerminatorKind::DropAndReplace { target, unwind, .. } |
@@ -303,9 +302,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
303302
},
304303
TerminatorKind::FalseEdges { real_target, ref imaginary_targets, .. } => {
305304
pending_locations.push(real_target.start_location());
306-
for target in imaginary_targets {
307-
pending_locations.push(target.start_location());
308-
}
305+
pending_locations.extend(
306+
imaginary_targets.into_iter().map(|target| target.start_location()));
309307
},
310308
_ => {},
311309
}

src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
462462
argument_hir_ty: &hir::Ty,
463463
counter: &mut usize,
464464
) -> Option<RegionName> {
465-
let search_stack: &mut Vec<(Ty<'tcx>, &hir::Ty)> = &mut Vec::new();
466-
467-
search_stack.push((argument_ty, argument_hir_ty));
465+
let search_stack: &mut Vec<(Ty<'tcx>, &hir::Ty)> =
466+
&mut vec![(argument_ty, argument_hir_ty)];
468467

469468
while let Some((ty, hir_ty)) = search_stack.pop() {
470469
match (&ty.sty, &hir_ty.node) {

0 commit comments

Comments
 (0)