]> git.lizzy.rs Git - rust.git/commitdiff
rustc: middle: avoid clones in ty_fn_{sig,args}.
authorEduard Burtescu <edy.burt@gmail.com>
Sat, 4 Oct 2014 15:36:06 +0000 (18:36 +0300)
committerEduard Burtescu <edy.burt@gmail.com>
Wed, 19 Nov 2014 04:24:35 +0000 (06:24 +0200)
src/librustc/middle/ty.rs
src/librustc_trans/trans/callee.rs

index 2aa50d90b09b129b40691fce2f17144957c974a0..eb94b57f52ca4082f76b2e04cd65d4716789bb0c 100644 (file)
@@ -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<Ty<'tcx>> {
-    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 {
index ae66d86b9941eacc82968080067b7e94e34b121d..c1a56dc96819d2253c1d9a70d7ce37375c4b97b0 100644 (file)
@@ -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)