Skip to content

Commit 9d14f4d

Browse files
committed
avoid some Vector allocations
1 parent c9e76eb commit 9d14f4d

File tree

1 file changed

+2
-7
lines changed
  • src/tools/miri/src/shims/native_lib

1 file changed

+2
-7
lines changed

src/tools/miri/src/shims/native_lib/ffi.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@ use libffi::middle::{Arg as ArgPtr, Cif, Type as FfiType};
99
///
1010
/// The safety invariants of the foreign function being called must be upheld (if any).
1111
pub unsafe fn call<R: libffi::high::CType>(fun: CodePtr, args: &mut [OwnedArg]) -> R {
12-
let mut cif_args = vec![];
13-
let mut arg_ptrs = vec![];
14-
for a in args {
15-
cif_args.push(a.ty.take().unwrap());
16-
arg_ptrs.push(ArgPtr::new(&*a.bytes));
17-
}
18-
let cif = Cif::new(cif_args, R::reify().into_middle());
12+
let cif = Cif::new(args.iter_mut().map(|arg| arg.ty.take().unwrap()), R::reify().into_middle());
13+
let arg_ptrs: Vec<_> = args.iter().map(|arg| ArgPtr::new(&*arg.bytes)).collect();
1914
// SAFETY: Caller upholds that the function is safe to call.
2015
unsafe { cif.call(fun, &arg_ptrs) }
2116
}

0 commit comments

Comments
 (0)