Use a Cow for the resumable parameters

This commit is contained in:
Pierre Krieger 2019-09-08 11:59:48 +02:00
parent 08c09adbf2
commit 171ce9daa6
No known key found for this signature in database
GPG Key ID: EE749C4F41D4EA47
1 changed files with 6 additions and 4 deletions

View File

@ -1,4 +1,5 @@
use alloc::{ use alloc::{
borrow::Cow,
rc::{Rc, Weak}, rc::{Rc, Weak},
vec::Vec, vec::Vec,
}; };
@ -195,12 +196,13 @@ impl FuncInstance {
/// [`resume_execution`]: struct.FuncInvocation.html#method.resume_execution /// [`resume_execution`]: struct.FuncInvocation.html#method.resume_execution
pub fn invoke_resumable<'args>( pub fn invoke_resumable<'args>(
func: &FuncRef, func: &FuncRef,
args: &'args [RuntimeValue], args: impl Into<Cow<'args, [RuntimeValue]>>,
) -> Result<FuncInvocation<'args>, Trap> { ) -> Result<FuncInvocation<'args>, Trap> {
let args = args.into();
check_function_args(func.signature(), &args)?; check_function_args(func.signature(), &args)?;
match *func.as_internal() { match *func.as_internal() {
FuncInstanceInternal::Internal { .. } => { FuncInstanceInternal::Internal { .. } => {
let interpreter = Interpreter::new(func, args, None)?; let interpreter = Interpreter::new(func, &*args, None)?;
Ok(FuncInvocation { Ok(FuncInvocation {
kind: FuncInvocationKind::Internal(interpreter), kind: FuncInvocationKind::Internal(interpreter),
}) })
@ -257,7 +259,7 @@ pub struct FuncInvocation<'args> {
enum FuncInvocationKind<'args> { enum FuncInvocationKind<'args> {
Internal(Interpreter), Internal(Interpreter),
Host { Host {
args: &'args [RuntimeValue], args: Cow<'args, [RuntimeValue]>,
host_func_index: usize, host_func_index: usize,
finished: bool, finished: bool,
}, },
@ -304,7 +306,7 @@ impl<'args> FuncInvocation<'args> {
return Err(ResumableError::AlreadyStarted); return Err(ResumableError::AlreadyStarted);
} }
*finished = true; *finished = true;
Ok(externals.invoke_index(*host_func_index, args.clone().into())?) Ok(externals.invoke_index(*host_func_index, args.as_ref().into())?)
} }
} }
} }