From be6cb63fcc13fc52457b5fa2199711740ea08716 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 30 Dec 2019 23:09:35 +0100 Subject: [PATCH] Reduce allocations. --- src/librustc/hir/lowering.rs | 14 ++++++-------- src/librustc/hir/lowering/item.rs | 2 +- src/librustc/lib.rs | 1 + 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 8f9de3f4277e..1aade0295852 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -73,12 +73,10 @@ use rustc_error_codes::*; macro_rules! arena_vec { - () => ( - &[] - ); - ($this:expr; $($x:expr),*) => ( - $this.arena.alloc_from_iter(vec![$($x),*]) - ); + ($this:expr; $($x:expr),*) => ({ + let a = [$($x),*]; + $this.arena.alloc_from_iter(std::array::IntoIter::new(a)) + }); } mod expr; @@ -2018,7 +2016,7 @@ fn lower_parenthesized_parameter_data( FunctionRetTy::Ty(ty) => this.lower_ty(&ty, ImplTraitContext::disallowed()), FunctionRetTy::Default(_) => this.arena.alloc(this.ty_tup(span, &[])), }; - let args = vec![GenericArg::Type(this.ty_tup(span, inputs))]; + let args = smallvec![GenericArg::Type(this.ty_tup(span, inputs))]; let binding = hir::TypeBinding { hir_id: this.next_id(), ident: Ident::with_dummy_span(FN_OUTPUT_NAME), @@ -3300,7 +3298,7 @@ fn body_ids(bodies: &BTreeMap>) -> Vec /// Helper struct for delayed construction of GenericArgs. struct GenericArgsCtor<'hir> { - args: Vec>, + args: SmallVec<[hir::GenericArg<'hir>; 1]>, bindings: &'hir [hir::TypeBinding<'hir>], parenthesized: bool, } diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index 37450b25d852..8c34aed5d5f5 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -1424,7 +1424,7 @@ fn lower_where_predicate(&mut self, pred: &WherePredicate) -> hir::WherePredicat /// Helper struct for delayed construction of Generics. pub(super) struct GenericsCtor<'hir> { - pub(super) params: Vec>, + pub(super) params: SmallVec<[hir::GenericParam<'hir>; 1]>, where_clause: hir::WhereClause<'hir>, span: Span, } diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 76588dfa5e25..4e7913b8dfc0 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -28,6 +28,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] #![feature(arbitrary_self_types)] +#![feature(array_value_iter)] #![feature(bool_to_option)] #![feature(box_patterns)] #![feature(box_syntax)]