Re: upvalues and polymorphism
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: upvalues and polymorphism
- From: Roberto Ierusalimschy <roberto@...>
- Date: 1998年5月17日 12:37:27 -0300
> In fact, for this specific reason, I'd like to see the "lookup" VM codes
> dereference a complete table lookup, instead of just one slot. It would be
> much more efficient to come up with a cache method for:
>
> ...
>
> Am I wrong in assuming that table lookup is somewhat costly in lua?
As lhf aswered, table lookup takes constant time in Lua. The constant can be
a little heavy, but not too much... Just in case, it is important to remember
that, in critical cases, a local variable can be explicitly used to "cache"
table lookups. As a tipical example, the following loop
local i = 1
while i<=MAX do
obj:f(a.b.c.d[i])
i = i+1
end
can be rewritten as
local i = 1
local t = a.b.c.d
local f = obj.f
while i<=MAX do
f(obj, t[i])
i = i+1
end
with good impact on performance.
-- Roberto