lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Mark Hamburg wrote:
...
3. Look at ways of making pushing the comparison string faster. For example,
if you have a constant C string, you could store them in the registry keyed
by the constant address by implementing something like the following:

    void pushConstantString( lua_State* L, const char* s, size_t len ) {
        lua_pushlightuserdata( L, s );
        lua_rawget( L, LUA_REGISTRYINDEX );
        if( lua_isnil( L, -1 ) ) {
            lua_pop( L, 1 );
            lua_pushlstring( L, s, len );
            /* Save it in the registry. */
            lua_pushlightuserdata( L, s );
            lua_pushvalue( L, -2 );
            lua_rawset( L, LUA_REGISTRYINDEX );
        }
    }

Given that, you can then avoid repeated hashing of the string when pushing
it.

This is very similar to what I have tried with luaL_ref(), except that you are using a lightuserdata rather than an integer. The nice thing about using luaL_ref() is that it works for non-constant strings.

But I think I will just continue using the ad-hoc technique I am using now. At least that allows me to do little optimizations like:

    const char* prop = lua_tostring(L,-1);
    if (prop[0] == 'f' && prop[1] == 'o' && prop[2] == 'o') ...

Oh well, on to bigger issues!

Thanks for all the ideas...

--
chris marrin              ,""$, "As a general rule,don't solve puzzles
chris@marrin.com        b`    $  that open portals to Hell" ,,.
        ,.`           ,b`    ,`                            , 1$'
     ,|`             mP    ,`                              :$$'     ,mm
   ,b"              b"   ,`            ,mm      m$$    ,m         ,`P$$
  m$`             ,b`  .` ,mm        ,'|$P   ,|"1$`  ,b$P       ,`  :$1
 b$`             ,$: :,`` |$$      ,`   $$` ,|` ,$$,,`"$$     .`    :$|
b$|            _m$`,:`    :$1   ,`     ,$Pm|`    `    :$$,..;"'     |$:
P$b,      _;b$$b$1"       |$$ ,`      ,$$"             ``'          $$
 ```"```'"    `"`         `""`        ""`                          ,P`