[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Is it an optimization?
- From: Roberto Ierusalimschy <rieru@...>
- Date: Tue, 13 Nov 2001 10:31:02 -0600 (CST)
On Tue, 13 Nov 2001, Max Ischenko wrote:
> I'm using the following function:
>
> function foobar()
> local s = ''
> -- lengthy computation and printing report to s
> local t = {text=s}
> function foobar()
> return %t.text
> end
> return s
> end
>
> The purpose of rewriting the function is to use value computed in the
> first call. It works just fine.
Just a small improvement: You do not need the table around "s". Your new
function could be simply function foobar() return %s end
(You only need the "trick" with a table if you were going to change "s"
after creating the new function.)
> The question -- will GC be able to freed old contents of the foobar?
Sure.
> Doesn't %t ref. disables it?
The "%t" only prevents the collection of table "t" itself.
-- Roberto