about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2019-12-30 23:09:35 +0100
committerCamille GILLOT <gillot.camille@gmail.com>2019-12-30 23:09:35 +0100
commitbe6cb63fcc13fc52457b5fa2199711740ea08716 (patch)
tree71dc8bf3091f8901a40729413aed9bc3ada07d12
parent8f05d12c6778b524e9209a6a32cbfe617f92428c (diff)
downloadrust-be6cb63fcc13fc52457b5fa2199711740ea08716.tar.gz
rust-be6cb63fcc13fc52457b5fa2199711740ea08716.zip
Reduce allocations.
-rw-r--r--src/librustc/hir/lowering.rs14
-rw-r--r--src/librustc/hir/lowering/item.rs2
-rw-r--r--src/librustc/lib.rs1
3 files changed, 8 insertions, 9 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs
index 8f9de3f4277..1aade029585 100644
--- a/src/librustc/hir/lowering.rs
+++ b/src/librustc/hir/lowering.rs
@@ -73,12 +73,10 @@ use syntax_pos::Span;
 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 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
                 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<hir::BodyId, hir::Body<'hir>>) -> Vec<hir::BodyId>
 
 /// Helper struct for delayed construction of GenericArgs.
 struct GenericArgsCtor<'hir> {
-    args: Vec<hir::GenericArg<'hir>>,
+    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 37450b25d85..8c34aed5d5f 100644
--- a/src/librustc/hir/lowering/item.rs
+++ b/src/librustc/hir/lowering/item.rs
@@ -1424,7 +1424,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
 
 /// Helper struct for delayed construction of Generics.
 pub(super) struct GenericsCtor<'hir> {
-    pub(super) params: Vec<hir::GenericParam<'hir>>,
+    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 76588dfa5e2..4e7913b8dfc 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)]