[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua strings as "atoms"???
- From: Chris Marrin <chris@...>
- Date: Mon, 16 May 2005 20:37:27 -0700
Ben Sunshine-Hill wrote:
It makes the C code a bit uglier, but I try to use upvalues for all my
Lua string constants in C functions that need to be efficient. By
pre-interning the strings, string equality is reduced to a pointer
compare. Using the registry is another approach, and one that looks a
lot cleaner, but isn't quite as efficient.
That's a good idea. But why is the registry less efficient? Can't you
store a string in the registry and get back a numeric id that can be
handed back to the registry to get pushed just as fast as an upvalue? Or
is there some optimization in upvalues that make them faster?
The other question is still outstanding, though. If I give a string to
Lua, will it always give me back the same address in every call to
lua_tostring() for that same sequence of characters? Does this work
across GC cycles, for instance?
chris marrin ,""$,
firstname.lastname@example.org b` $ ,,.
(408) 955-3049 mP b' , 1$'
Sony ,.` ,b` ,` :$$'
,|` 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`
"As a general rule,don't solve puzzles that open portals to Hell"'