[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: ways to avoid (or speed up) luaL_checkudata() in LuaJIT2?
- From: Mike Pall <mikelu-1011@...>
- Date: Sat, 6 Nov 2010 11:12:01 +0100
Stefan Behnel wrote:
> From looking at the function in LuaJIT2 (2.0.0-beta5), it basically
> only calls internal functions, so it's not clear to me what I can do
> to avoid the call.
Yes, I've optimized this one as much as possible. The real issue
is that the design of the luaL_*udata API functions is suboptimal.
But you don't need to use these at all.
You can either follow Luiz suggestions or here are some more:
- Create all userdata methods with the C function environment
holding a reference to the userdata metatable. Then you can
just use lua_getmetatable() + lua_rawequal().
- Or use a C function upvalue, if the environment table is already
used for something else.
[Actually the internal userdata methods in LuaJIT have a much
faster check, using a 16 bit udtype field in every userdata. See
io_tofilep() in lib_io.c. Alas, this mechanism is not available
for external methods and it might change anytime.]
--Mike