lua-users home
lua-l archive

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


> A couple trivial optimization change: move the following line:
> 
>     local byte, rep = string.byte, string.rep
> 
> out of the function.  The string table look-ups happen every single
> call, rather than only once at load time. 
> 
> It is also possible that lifting string.sub and string.gsub out the same
> way as byte and rep and using them via upvalue may be faster than doing
> a metatable look-up each time through.

"Each time" here means once for every encoding. If you encode a small
message, with ~1KB, the inner function will be called ~300 times, while
the 'bs' table will be indexed ~1200 times. Will a few extra table
lookups make any difference?

-- Roberto