diff options
author | Alex Orlenko <zxteam@protonmail.com> | 2022-01-29 12:39:30 +0000 |
---|---|---|
committer | Alex Orlenko <zxteam@protonmail.com> | 2022-01-29 12:39:30 +0000 |
commit | f9fe869b76da2f71f88655f4b9d44871f6a28ed2 (patch) | |
tree | 16f4d7f650db3f4c52b6d8444e559c8edebec38e /src | |
parent | 6e4033abba37b7a9bbeb1c58daafb9649cc93c8c (diff) | |
download | mlua-f9fe869b76da2f71f88655f4b9d44871f6a28ed2.zip |
Optimize async calls:
Rewrite "unpack" function using C api rather than high level abstraction.
Diffstat (limited to 'src')
-rw-r--r-- | src/lua.rs | 19 | ||||
-rw-r--r-- | src/table.rs | 2 |
2 files changed, 12 insertions, 9 deletions
@@ -2400,19 +2400,22 @@ impl Lua { Function(self.pop_ref()) }; + unsafe extern "C" fn unpack(state: *mut ffi::lua_State) -> c_int { + let len = ffi::lua_tointeger(state, 2); + for i in 1..=len { + ffi::lua_rawgeti(state, 1, i); + } + len as c_int + } + let coroutine = self.globals().get::<_, Table>("coroutine")?; let env = self.create_table_with_capacity(0, 4)?; env.set("get_poll", get_poll)?; env.set("yield", coroutine.get::<_, Function>("yield")?)?; - env.set( - "unpack", - self.create_function(|lua, (tbl, len): (Table, Integer)| { - let mut values = MultiValue::new_or_cached(lua); - values.refill(tbl.raw_sequence_values_by_len(Some(len)))?; - Ok(values) - })?, - )?; + unsafe { + env.set("unpack", self.create_c_function(unpack)?)?; + } env.set("pending", { LightUserData(&ASYNC_POLL_PENDING as *const u8 as *mut c_void) })?; diff --git a/src/table.rs b/src/table.rs index 4f8c1bc..80c9fc6 100644 --- a/src/table.rs +++ b/src/table.rs @@ -455,7 +455,7 @@ impl<'lua> Table<'lua> { } } - #[cfg(any(feature = "async", feature = "serialize"))] + #[cfg(any(feature = "serialize"))] pub(crate) fn raw_sequence_values_by_len<V: FromLua<'lua>>( self, len: Option<Integer>, |