summaryrefslogtreecommitdiff
path: root/src/lua.rs
diff options
context:
space:
mode:
authorAlex Orlenko <zxteam@protonmail.com>2021-06-20 12:38:47 +0100
committerAlex Orlenko <zxteam@protonmail.com>2021-06-20 12:38:47 +0100
commit42b396d0d117814731d0b07c75bbb01deb136ab7 (patch)
tree24f3dd96e554f368d6a3e8ed34cb4df97b90dbff /src/lua.rs
parent14d5c2c8876fa9e2471096a1533e0df90fdfbcbd (diff)
downloadmlua-42b396d0d117814731d0b07c75bbb01deb136ab7.zip
Optimize non-wrapped userdata method calls
Diffstat (limited to 'src/lua.rs')
-rw-r--r--src/lua.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/lua.rs b/src/lua.rs
index ef977a9..326b74f 100644
--- a/src/lua.rs
+++ b/src/lua.rs
@@ -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>>>()?;