lua-users home
lua-l archive

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


>> Date: Thu, 22 Jan 2009 07:37:20 -0500 (EST)
>> From: Leo Razoumov
> In Lua, on the other hand, some
> optimizations make code *MORE* readable.

Here's one optimization that is less readable:

  local y = myvar^4 / (1 + myvar^2)

  local x2 = myvar*myvar
  local y = x2*x2 / (1 + x2)
  -- Lua itself couldn't do this factorization due to
  -- the possibility not only of overflow but also
  -- metamethods, except in special cases if detected
  -- by code analysis

and another:

  table.insert(table1.table2, 1)

  local t = table1.table2; t[#t+1] = 0

Compile time macros could improve both cases above though.  Also,
Lua's constant folding (which might be considered related to that)
avoids the temptation of doing some less readable optimizations (e.g.
when given y = (2/3)*x).