Hello all,
After profiling some C extensions I had written, I noticed that many
of my fast routines spent an enormous percentage of time (60% or more)
calling luaL_checkudata, and most of that was spent in its strcmp call.
I wrote a faster routine that works on pointers, and should work for
both userdata and tables.
Is there are problem using this technique, assuming the metatables I'm
comparing are allocated in a library's luaopen_XXX function and only
freed on a lua_close() call?
void* fastcheckudata( lua_State* L, int index, const char* id)
{
lua_getmetatable(L,index);
const void* p1 = lua_topointer(L,-1);
luaL_getmetatable(L,id);
const void* p2 = lua_topointer(L,-1);
lua_pop(L,2);
return p1 == p2 ? lua_touserdata(L, index) : NULL;
}
Best,