- Joined
- Sep 26, 2009
- Messages
- 9,534
This small snippet will cut the number of tables produced by __jarray almost by 50%. The regular __jarray function currently produces two tables per initialization due to the setmetatable call, however this will instead cache the metatables with the same default return value and recycle them.
Lua:
do --__jarray compactor 1.0 by Bribe
local mts = {}
function __jarray(default)
if default then
local mt = mts[default]
if not mt then
mt = {__index = function() return default end}
mts[default] = mt
end
return setmetatable({}, mt)
end
return {}
end
end