• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Lua] [Deprecated] __jarray Compactor (GUI helper)

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
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
 
Top