Skip to content

Commit 01105ff

Browse files
committed
rustc: middle: avoid clones in ty_fn_{sig,args}.
1 parent 4c3ad48 commit 01105ff

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

src/librustc/middle/ty.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3545,10 +3545,10 @@ pub fn fn_is_variadic(fty: Ty) -> bool {
35453545
}
35463546
}
35473547

3548-
pub fn ty_fn_sig<'tcx>(fty: Ty<'tcx>) -> FnSig<'tcx> {
3548+
pub fn ty_fn_sig<'tcx>(fty: Ty<'tcx>) -> &'tcx FnSig<'tcx> {
35493549
match get(fty).sty {
3550-
ty_bare_fn(ref f) => f.sig.clone(),
3551-
ty_closure(ref f) => f.sig.clone(),
3550+
ty_bare_fn(ref f) => &f.sig,
3551+
ty_closure(ref f) => &f.sig,
35523552
ref s => {
35533553
panic!("ty_fn_sig() called on non-fn type: {}", s)
35543554
}
@@ -3565,14 +3565,8 @@ pub fn ty_fn_abi(fty: Ty) -> abi::Abi {
35653565
}
35663566

35673567
// Type accessors for substructures of types
3568-
pub fn ty_fn_args<'tcx>(fty: Ty<'tcx>) -> Vec<Ty<'tcx>> {
3569-
match get(fty).sty {
3570-
ty_bare_fn(ref f) => f.sig.inputs.clone(),
3571-
ty_closure(ref f) => f.sig.inputs.clone(),
3572-
ref s => {
3573-
panic!("ty_fn_args() called on non-fn type: {}", s)
3574-
}
3575-
}
3568+
pub fn ty_fn_args<'tcx>(fty: Ty<'tcx>) -> &'tcx [Ty<'tcx>] {
3569+
ty_fn_sig(fty).inputs.as_slice()
35763570
}
35773571

35783572
pub fn ty_closure_store(fty: Ty) -> TraitStore {

src/librustc_trans/trans/callee.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,7 @@ pub fn trans_unboxing_shim<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
334334
// Create the substituted versions of the self type.
335335
let arg_scope = fcx.push_custom_cleanup_scope();
336336
let arg_scope_id = cleanup::CustomScope(arg_scope);
337-
let boxed_arg_types = ty::ty_fn_args(boxed_function_type);
338-
let boxed_self_type = boxed_arg_types[0];
337+
let boxed_self_type = ty::ty_fn_args(boxed_function_type)[0];
339338
let arg_types = ty::ty_fn_args(function_type);
340339
let self_type = arg_types[0];
341340
let boxed_self_kind = arg_kind(&fcx, boxed_self_type);
@@ -919,12 +918,11 @@ fn trans_args_under_call_abi<'blk, 'tcx>(
919918
ignore_self: bool)
920919
-> Block<'blk, 'tcx> {
921920
// Translate the `self` argument first.
922-
let arg_tys = ty::ty_fn_args(fn_ty);
923921
if !ignore_self {
924922
let arg_datum = unpack_datum!(bcx, expr::trans(bcx, &*arg_exprs[0]));
925923
llargs.push(unpack_result!(bcx, {
926924
trans_arg_datum(bcx,
927-
arg_tys[0],
925+
ty::ty_fn_args(fn_ty)[0],
928926
arg_datum,
929927
arg_cleanup_scope,
930928
DontAutorefArg)

0 commit comments

Comments
 (0)