[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua_setfield vs lua_rawset
- From: Rici Lake <lua@...>
- Date: Wed, 19 Oct 2005 12:22:31 -0500
On 19-Oct-05, at 12:00 PM, Chris Marrin wrote:
But the decision was made to provide the particular variant of
lua_setfield(), which is extremely useful. And since the "raw"
variants add a useful (and sometimes critical) optimization of their
own, it seems that the equivalent lua_rawsetfield() would have been a
good choice.
Have you actually benchmarked the difference in performance between
lua_settable() and lua_rawset()? It seems to me to be hardly noticeable
in the normal case. (That's not the same situation as lua_rawseti().)
Using lua_rawset() instead of lua_settable() produces surprising
results (surprising to the client of the library, that is) because it
doesn't respect metatables. There is no difference when the table has
no metatable, or when the key already exists.
I would strongly discourage use of rawset except in cases where it is
actually necessary because you have to bypass the __newindex
metamethod. Such cases are quite rare (usually confined to
implementation of __newindex itself).