Skip to content

Commit cb428a6

Browse files
committed
rustc: middle: avoid clones in ty_fn_{sig,args}.
1 parent 9740643 commit cb428a6

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

src/librustc/middle/trans/callee.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,7 @@ pub fn trans_unboxing_shim<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
331331
// Create the substituted versions of the self type.
332332
let arg_scope = fcx.push_custom_cleanup_scope();
333333
let arg_scope_id = cleanup::CustomScope(arg_scope);
334-
let boxed_arg_types = ty::ty_fn_args(boxed_function_type);
335-
let boxed_self_type = boxed_arg_types[0];
334+
let boxed_self_type = ty::ty_fn_args(boxed_function_type)[0];
336335
let arg_types = ty::ty_fn_args(function_type);
337336
let self_type = arg_types[0];
338337
let boxed_self_kind = arg_kind(&fcx, boxed_self_type);
@@ -912,12 +911,11 @@ fn trans_args_under_call_abi<'blk, 'tcx>(
912911
ignore_self: bool)
913912
-> Block<'blk, 'tcx> {
914913
// Translate the `self` argument first.
915-
let arg_tys = ty::ty_fn_args(fn_ty);
916914
if !ignore_self {
917915
let arg_datum = unpack_datum!(bcx, expr::trans(bcx, &*arg_exprs[0]));
918916
llargs.push(unpack_result!(bcx, {
919917
trans_arg_datum(bcx,
920-
arg_tys[0],
918+
ty::ty_fn_args(fn_ty)[0],
921919
arg_datum,
922920
arg_cleanup_scope,
923921
DontAutorefArg)

src/librustc/middle/ty.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3331,10 +3331,10 @@ pub fn fn_is_variadic(fty: Ty) -> bool {
33313331
}
33323332
}
33333333

3334-
pub fn ty_fn_sig<'tcx>(fty: Ty<'tcx>) -> FnSig<'tcx> {
3334+
pub fn ty_fn_sig<'tcx>(fty: Ty<'tcx>) -> &'tcx FnSig<'tcx> {
33353335
match get(fty).sty {
3336-
ty_bare_fn(ref f) => f.sig.clone(),
3337-
ty_closure(ref f) => f.sig.clone(),
3336+
ty_bare_fn(ref f) => &f.sig,
3337+
ty_closure(ref f) => &f.sig,
33383338
ref s => {
33393339
panic!("ty_fn_sig() called on non-fn type: {}", s)
33403340
}
@@ -3351,14 +3351,8 @@ pub fn ty_fn_abi(fty: Ty) -> abi::Abi {
33513351
}
33523352

33533353
// Type accessors for substructures of types
3354-
pub fn ty_fn_args<'tcx>(fty: Ty<'tcx>) -> Vec<Ty<'tcx>> {
3355-
match get(fty).sty {
3356-
ty_bare_fn(ref f) => f.sig.inputs.clone(),
3357-
ty_closure(ref f) => f.sig.inputs.clone(),
3358-
ref s => {
3359-
panic!("ty_fn_args() called on non-fn type: {}", s)
3360-
}
3361-
}
3354+
pub fn ty_fn_args<'tcx>(fty: Ty<'tcx>) -> &'tcx [Ty<'tcx>] {
3355+
ty_fn_sig(fty).inputs.as_slice()
33623356
}
33633357

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

0 commit comments

Comments
 (0)