Don't clone function when doing call_async()

This commit is contained in:
Alex Orlenko 2023-06-21 13:14:17 +01:00
parent c1168d3ec1
commit 1367a033d7
No known key found for this signature in database
GPG Key ID: 4C150C250863B96D
1 changed files with 8 additions and 1 deletions

View File

@ -1628,6 +1628,13 @@ impl Lua {
///
/// Equivalent to `coroutine.create`.
pub fn create_thread<'lua>(&'lua self, func: Function) -> Result<Thread<'lua>> {
self.create_thread_inner(&func)
}
/// Wraps a Lua function into a new thread (or coroutine).
///
/// Takes function by reference.
fn create_thread_inner<'lua>(&'lua self, func: &Function) -> Result<Thread<'lua>> {
let state = self.state();
unsafe {
let _sg = StackGuard::new(state);
@ -1676,7 +1683,7 @@ impl Lua {
return Ok(Thread(LuaRef::new(self, index)));
}
};
self.create_thread(func.clone())
self.create_thread_inner(func)
}
/// Resets thread (coroutine) and returns to the pool for later use.