[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: A proposal for faster userdata type checking
- From: Richter, Jörg <Joerg.Richter@...>
- Date: Fri, 29 Feb 2008 09:03:53 +0100
>>
>> So to set a userdata to a class, you only need one rawget,
>> using a lightuserdata as key, from the class table (which
>> can be the registry or a private table in an upvalue), plus
>> one setmetatable.
>>
>> To check a userdata you need one touserdata, that one rawget,
>> one getmetatable, and one isequal.
>>
>> The savings come from the fact you don't traverse strings,
>> ever, and you don't create strings, ever.
>>
>
>I agree with the above.
>
>I don't have the numbers anymore, but wxLua has switched to using
>lightuserdata table keys as well. For example, we push lightuserdata
>of the address of const char* strings as keys to our tables in the
>LUA_REGISTRYINDEX.
I do the same. But storing the key in LUA_REGISTRYINDEX seems like a potential problem to me.
Imagine two libraries storing the same constant string in the registry. It can happen (static linking?) that the two strings have the same address. This is not possible with the address of 'static char' or 'static char[]'
Jörg