Skip to content

Commit 6b5edd2

Browse files
committed
Avoid a needless vector copy in type_of_rust_fn
1 parent 95c08e3 commit 6b5edd2

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/librustc_trans/trans/type_of.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,11 @@ pub fn type_of_explicit_arg<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
5454
}
5555
}
5656

57-
/// Yields the types of the "real" arguments for this function. For most
58-
/// functions, these are simply the types of the arguments. For functions with
59-
/// the `RustCall` ABI, however, this untuples the arguments of the function.
60-
pub fn untuple_arguments_if_necessary<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
61-
inputs: &[Ty<'tcx>],
62-
abi: abi::Abi)
63-
-> Vec<Ty<'tcx>> {
64-
if abi != abi::RustCall {
65-
return inputs.iter().cloned().collect()
66-
}
67-
57+
/// Yields the types of the "real" arguments for a function using the `RustCall`
58+
/// ABI by untupling the arguments of the function.
59+
pub fn untuple_arguments<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
60+
inputs: &[Ty<'tcx>])
61+
-> Vec<Ty<'tcx>> {
6862
if inputs.is_empty() {
6963
return Vec::new()
7064
}
@@ -78,7 +72,7 @@ pub fn untuple_arguments_if_necessary<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
7872

7973
match inputs[inputs.len() - 1].sty {
8074
ty::TyTuple(ref tupled_arguments) => {
81-
debug!("untuple_arguments_if_necessary(): untupling arguments");
75+
debug!("untuple_arguments(): untupling arguments");
8276
for &tupled_argument in tupled_arguments {
8377
result.push(tupled_argument);
8478
}
@@ -108,7 +102,11 @@ pub fn type_of_rust_fn<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
108102
let mut atys: Vec<Type> = Vec::new();
109103

110104
// First, munge the inputs, if this has the `rust-call` ABI.
111-
let inputs = untuple_arguments_if_necessary(cx, &sig.inputs, abi);
105+
let inputs = &if abi == abi::RustCall {
106+
untuple_arguments(cx, &sig.inputs)
107+
} else {
108+
sig.inputs
109+
};
112110

113111
// Arg 0: Output pointer.
114112
// (if the output type is non-immediate)
@@ -136,7 +134,7 @@ pub fn type_of_rust_fn<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
136134
}
137135

138136
// ... then explicit args.
139-
for input in &inputs {
137+
for input in inputs {
140138
let arg_ty = type_of_explicit_arg(cx, input);
141139

142140
if type_is_fat_ptr(cx.tcx(), input) {

0 commit comments

Comments
 (0)