lua-users home
lua-l archive

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


On 21/04/2011, at 9:39 AM, Valerio Schiavoni wrote:

> Hello Geoff,
> 
> On Wed, Apr 20, 2011 at 11:32 PM, Geoff Leyland
> <geoff_leyland@fastmail.fm> wrote:
> 
>> It looks like most of the time is spent concatenating strings on the lines
>> out = out..encode(v)
>> and
>> return out..'e'
>> 
>> Have you tried making 'out' a table, appending strings to it and then doing a table.concat as you return it?
> 
> i tried that as the first thing, and the optimization gain was unnoticeable.

How about having encode do this:

function encode(data)
  local out = { n=1}
  encode_table(data,  out)
  return table.concat(out)
end

and encode_data contains lines like:

  encode_table(v, out)

rather than

  out = out..encode(v)


Cheers,
Geoff