Skip to content

Commit

Permalink
Avoid a few allocations.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Dec 30, 2019
1 parent 2d74e9b commit 4d77382
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
24 changes: 13 additions & 11 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1890,7 +1890,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
if !generic_args.parenthesized && !has_lifetimes {
generic_args.args = self
.elided_path_lifetimes(path_span, expected_lifetimes)
.into_iter()
.map(|lt| GenericArg::Lifetime(lt))
.chain(generic_args.args.into_iter())
.collect();
Expand Down Expand Up @@ -2460,16 +2459,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::Lifetime { hir_id: self.lower_node_id(id), span, name }
}

fn lower_generic_params_mut(
&mut self,
params: &[GenericParam],
add_bounds: &NodeMap<Vec<GenericBound>>,
mut itctx: ImplTraitContext<'_, 'hir>,
) -> Vec<hir::GenericParam<'hir>> {
fn lower_generic_params_mut<'s>(
&'s mut self,
params: &'s [GenericParam],
add_bounds: &'s NodeMap<Vec<GenericBound>>,
mut itctx: ImplTraitContext<'s, 'hir>,
) -> impl Iterator<Item = hir::GenericParam<'hir>> + Captures<'a> + Captures<'s> {
params
.iter()
.map(|param| self.lower_generic_param(param, add_bounds, itctx.reborrow()))
.collect()
.map(move |param| self.lower_generic_param(param, add_bounds, itctx.reborrow()))
}

fn lower_generic_params(
Expand Down Expand Up @@ -3200,8 +3198,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
/// `std::cell::Ref<T>`; note that implicit lifetimes in these
/// sorts of cases are deprecated. This may therefore report a warning or an
/// error, depending on the mode.
fn elided_path_lifetimes(&mut self, span: Span, count: usize) -> Vec<hir::Lifetime> {
(0..count).map(|_| self.elided_path_lifetime(span)).collect()
fn elided_path_lifetimes<'s>(
&'s mut self,
span: Span,
count: usize,
) -> impl Iterator<Item = hir::Lifetime> + Captures<'a> + Captures<'s> + Captures<'hir> {
(0..count).map(move |_| self.elided_path_lifetime(span))
}

fn elided_path_lifetime(&mut self, span: Span) -> hir::Lifetime {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

GenericsCtor {
params: self.lower_generic_params_mut(&generics.params, &add_bounds, itctx),
params: self.lower_generic_params_mut(&generics.params, &add_bounds, itctx).collect(),
where_clause: self.lower_where_clause(&generics.where_clause),
span: generics.span,
}
Expand Down

0 comments on commit 4d77382

Please sign in to comment.