Skip to content

Commit be6cb63

Browse files
committed
Reduce allocations.
1 parent 8f05d12 commit be6cb63

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/librustc/hir/lowering.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,10 @@ use syntax_pos::Span;
7373
use rustc_error_codes::*;
7474

7575
macro_rules! arena_vec {
76-
() => (
77-
&[]
78-
);
79-
($this:expr; $($x:expr),*) => (
80-
$this.arena.alloc_from_iter(vec![$($x),*])
81-
);
76+
($this:expr; $($x:expr),*) => ({
77+
let a = [$($x),*];
78+
$this.arena.alloc_from_iter(std::array::IntoIter::new(a))
79+
});
8280
}
8381

8482
mod expr;
@@ -2018,7 +2016,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20182016
FunctionRetTy::Ty(ty) => this.lower_ty(&ty, ImplTraitContext::disallowed()),
20192017
FunctionRetTy::Default(_) => this.arena.alloc(this.ty_tup(span, &[])),
20202018
};
2021-
let args = vec![GenericArg::Type(this.ty_tup(span, inputs))];
2019+
let args = smallvec![GenericArg::Type(this.ty_tup(span, inputs))];
20222020
let binding = hir::TypeBinding {
20232021
hir_id: this.next_id(),
20242022
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>
33003298

33013299
/// Helper struct for delayed construction of GenericArgs.
33023300
struct GenericArgsCtor<'hir> {
3303-
args: Vec<hir::GenericArg<'hir>>,
3301+
args: SmallVec<[hir::GenericArg<'hir>; 1]>,
33043302
bindings: &'hir [hir::TypeBinding<'hir>],
33053303
parenthesized: bool,
33063304
}

src/librustc/hir/lowering/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14241424

14251425
/// Helper struct for delayed construction of Generics.
14261426
pub(super) struct GenericsCtor<'hir> {
1427-
pub(super) params: Vec<hir::GenericParam<'hir>>,
1427+
pub(super) params: SmallVec<[hir::GenericParam<'hir>; 1]>,
14281428
where_clause: hir::WhereClause<'hir>,
14291429
span: Span,
14301430
}

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
2929
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
3030
#![feature(arbitrary_self_types)]
31+
#![feature(array_value_iter)]
3132
#![feature(bool_to_option)]
3233
#![feature(box_patterns)]
3334
#![feature(box_syntax)]

0 commit comments

Comments
 (0)