From 7b29c7803588a6f885dd01bcdedd32c769db17ee Mon Sep 17 00:00:00 2001 From: Riccardo Mazzarini Date: Sun, 2 Apr 2023 13:09:46 +0200 Subject: [PATCH] refactor `<()>::pop()` --- crates/luajit-bindings/src/poppable.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/crates/luajit-bindings/src/poppable.rs b/crates/luajit-bindings/src/poppable.rs index ae62f3e5..06091d6d 100644 --- a/crates/luajit-bindings/src/poppable.rs +++ b/crates/luajit-bindings/src/poppable.rs @@ -12,17 +12,15 @@ pub trait Poppable: Sized { } impl Poppable for () { + #[inline(always)] unsafe fn pop(state: *mut lua_State) -> Result { if lua_gettop(state) == 0 { - return Ok(()); - } - - match lua_type(state, -1) { - LUA_TNIL => { - lua_pop(state, 1); - Ok(()) - }, - other => Err(Error::pop_wrong_type::(LUA_TNIL, other)), + Ok(()) + } else if lua_type(state, -1) == LUA_TNIL { + lua_pop(state, 1); + Ok(()) + } else { + Err(Error::pop_wrong_type::(LUA_TNIL, lua_type(state, -1))) } } }