diff options
author | Alex Orlenko <zxteam@protonmail.com> | 2021-06-20 12:38:47 +0100 |
---|---|---|
committer | Alex Orlenko <zxteam@protonmail.com> | 2021-06-20 12:38:47 +0100 |
commit | 42b396d0d117814731d0b07c75bbb01deb136ab7 (patch) | |
tree | 24f3dd96e554f368d6a3e8ed34cb4df97b90dbff /src/lua.rs | |
parent | 14d5c2c8876fa9e2471096a1533e0df90fdfbcbd (diff) | |
download | mlua-42b396d0d117814731d0b07c75bbb01deb136ab7.zip |
Optimize non-wrapped userdata method calls
Diffstat (limited to 'src/lua.rs')
-rw-r--r-- | src/lua.rs | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -2694,11 +2694,15 @@ impl<'lua, T: 'static + UserData> StaticUserDataMethods<'lua, T> { Box::new(move |lua, mut args| { if let Some(front) = args.pop_front() { let userdata = AnyUserData::from_lua(front, lua)?; - match userdata.type_id()? { - id if id == TypeId::of::<T>() => { - let ud = userdata.borrow::<T>()?; - method(lua, &ud, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua) + // Try normal userdata first + let err = match userdata.borrow::<T>() { + Ok(ud) => { + return method(lua, &ud, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua) } + Err(err) => err, + }; + match userdata.type_id()? { + id if id == TypeId::of::<T>() => Err(err), #[cfg(not(feature = "send"))] id if id == TypeId::of::<Rc<RefCell<T>>>() => { let ud = userdata.borrow::<Rc<RefCell<T>>>()?; |