From 4516ca0bb52635ed6a310fc2e9ce56a441d675c5 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Tue, 7 Jun 2022 17:59:22 +0100 Subject: [PATCH] Forgotten part of userdata performance optimization for Lua 5.1 --- src/lua.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lua.rs b/src/lua.rs index fd8bab7..5efbe55 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -2822,10 +2822,15 @@ impl Lua { // Set empty environment for Lua 5.1 #[cfg(any(feature = "lua51", feature = "luajit"))] - protect_lua!(self.state, 1, 1, fn(state) { - ffi::lua_newtable(state); - ffi::lua_setuservalue(state, -2); - })?; + if protect { + protect_lua!(self.state, 1, 1, fn(state) { + ffi::lua_newtable(state); + ffi::lua_setuservalue(state, -2); + })?; + } else { + ffi::lua_newtable(self.state); + ffi::lua_setuservalue(self.state, -2); + } Ok(AnyUserData(self.pop_ref())) }