From 01105ffde363bff46ebe16d032edb7a538609e18 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sat, 4 Oct 2014 18:36:06 +0300 Subject: [PATCH] rustc: middle: avoid clones in ty_fn_{sig,args}. --- src/librustc/middle/ty.rs | 16 +++++----------- src/librustc_trans/trans/callee.rs | 6 ++---- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 2aa50d90b09..eb94b57f52c 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3545,10 +3545,10 @@ pub fn fn_is_variadic(fty: Ty) -> bool { } } -pub fn ty_fn_sig<'tcx>(fty: Ty<'tcx>) -> FnSig<'tcx> { +pub fn ty_fn_sig<'tcx>(fty: Ty<'tcx>) -> &'tcx FnSig<'tcx> { match get(fty).sty { - ty_bare_fn(ref f) => f.sig.clone(), - ty_closure(ref f) => f.sig.clone(), + ty_bare_fn(ref f) => &f.sig, + ty_closure(ref f) => &f.sig, ref s => { panic!("ty_fn_sig() called on non-fn type: {}", s) } @@ -3565,14 +3565,8 @@ pub fn ty_fn_abi(fty: Ty) -> abi::Abi { } // Type accessors for substructures of types -pub fn ty_fn_args<'tcx>(fty: Ty<'tcx>) -> Vec> { - match get(fty).sty { - ty_bare_fn(ref f) => f.sig.inputs.clone(), - ty_closure(ref f) => f.sig.inputs.clone(), - ref s => { - panic!("ty_fn_args() called on non-fn type: {}", s) - } - } +pub fn ty_fn_args<'tcx>(fty: Ty<'tcx>) -> &'tcx [Ty<'tcx>] { + ty_fn_sig(fty).inputs.as_slice() } pub fn ty_closure_store(fty: Ty) -> TraitStore { diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs index ae66d86b994..c1a56dc9681 100644 --- a/src/librustc_trans/trans/callee.rs +++ b/src/librustc_trans/trans/callee.rs @@ -334,8 +334,7 @@ pub fn trans_unboxing_shim<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, // Create the substituted versions of the self type. let arg_scope = fcx.push_custom_cleanup_scope(); let arg_scope_id = cleanup::CustomScope(arg_scope); - let boxed_arg_types = ty::ty_fn_args(boxed_function_type); - let boxed_self_type = boxed_arg_types[0]; + let boxed_self_type = ty::ty_fn_args(boxed_function_type)[0]; let arg_types = ty::ty_fn_args(function_type); let self_type = arg_types[0]; let boxed_self_kind = arg_kind(&fcx, boxed_self_type); @@ -919,12 +918,11 @@ fn trans_args_under_call_abi<'blk, 'tcx>( ignore_self: bool) -> Block<'blk, 'tcx> { // Translate the `self` argument first. - let arg_tys = ty::ty_fn_args(fn_ty); if !ignore_self { let arg_datum = unpack_datum!(bcx, expr::trans(bcx, &*arg_exprs[0])); llargs.push(unpack_result!(bcx, { trans_arg_datum(bcx, - arg_tys[0], + ty::ty_fn_args(fn_ty)[0], arg_datum, arg_cleanup_scope, DontAutorefArg)