diff options
author | Rui914 <rui914t@gmail.com> | 2016-03-07 00:53:45 +0900 |
---|---|---|
committer | paramat <mat.gregory@virginmedia.com> | 2016-03-06 23:42:04 +0000 |
commit | 24e8b0ac1ea45719937948607259f13866c8bc64 (patch) | |
tree | f8bb110a59ca436d2a7a15686da8feab160a1c93 /builtin/game | |
parent | 75db0543f3df4b30ce23731f5008d0c9afa277ff (diff) | |
download | minetest-24e8b0ac1ea45719937948607259f13866c8bc64.tar.gz minetest-24e8b0ac1ea45719937948607259f13866c8bc64.tar.bz2 minetest-24e8b0ac1ea45719937948607259f13866c8bc64.zip |
Faster insertion into table
Diffstat (limited to 'builtin/game')
-rw-r--r-- | builtin/game/auth.lua | 2 | ||||
-rw-r--r-- | builtin/game/chatcommands.lua | 6 | ||||
-rw-r--r-- | builtin/game/misc.lua | 10 | ||||
-rw-r--r-- | builtin/game/register.lua | 8 |
4 files changed, 13 insertions, 13 deletions
diff --git a/builtin/game/auth.lua b/builtin/game/auth.lua index 423eb3134..deb811b14 100644 --- a/builtin/game/auth.lua +++ b/builtin/game/auth.lua @@ -20,7 +20,7 @@ function core.privs_to_string(privs, delim) local list = {} for priv, bool in pairs(privs) do if bool then - table.insert(list, priv) + list[#list + 1] = priv end end return table.concat(list, delim) diff --git a/builtin/game/chatcommands.lua b/builtin/game/chatcommands.lua index 6b4ca0d12..2c7a0b532 100644 --- a/builtin/game/chatcommands.lua +++ b/builtin/game/chatcommands.lua @@ -116,7 +116,7 @@ core.register_chatcommand("help", { local cmds = {} for cmd, def in pairs(core.chatcommands) do if core.check_player_privs(name, def.privs) then - table.insert(cmds, cmd) + cmds[#cmds + 1] = cmd end end table.sort(cmds) @@ -127,7 +127,7 @@ core.register_chatcommand("help", { local cmds = {} for cmd, def in pairs(core.chatcommands) do if core.check_player_privs(name, def.privs) then - table.insert(cmds, format_help_line(cmd, def)) + cmds[#cmds + 1] = format_help_line(cmd, def) end end table.sort(cmds) @@ -135,7 +135,7 @@ core.register_chatcommand("help", { elseif param == "privs" then local privs = {} for priv, def in pairs(core.registered_privileges) do - table.insert(privs, priv .. ": " .. def.description) + privs[#privs + 1] = priv .. ": " .. def.description end table.sort(privs) return true, "Available privileges:\n"..table.concat(privs, "\n") diff --git a/builtin/game/misc.lua b/builtin/game/misc.lua index d0e67bd88..4f58710d0 100644 --- a/builtin/game/misc.lua +++ b/builtin/game/misc.lua @@ -40,12 +40,12 @@ end) function core.after(after, func, ...) assert(tonumber(time) and type(func) == "function", "Invalid core.after invocation") - table.insert(jobs, { + jobs[#jobs + 1] = { func = func, expire = time + after, arg = {...}, mod_origin = core.get_last_run_mod() - }) + } end function core.check_player_privs(player_or_name, ...) @@ -63,14 +63,14 @@ function core.check_player_privs(player_or_name, ...) -- We were provided with a table like { privA = true, privB = true }. for priv, value in pairs(requested_privs[1]) do if value and not player_privs[priv] then - table.insert(missing_privileges, priv) + missing_privileges[#missing_privileges + 1] = priv end end else -- Only a list, we can process it directly. for key, priv in pairs(requested_privs) do if not player_privs[priv] then - table.insert(missing_privileges, priv) + missing_privileges[#missing_privileges + 1] = priv end end end @@ -96,7 +96,7 @@ function core.get_connected_players() local temp_table = {} for index, value in pairs(player_list) do if value:is_player_connected() then - table.insert(temp_table, value) + temp_table[#temp_table + 1] = value end end return temp_table diff --git a/builtin/game/register.lua b/builtin/game/register.lua index ba5f69d67..398daf057 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -75,7 +75,7 @@ end function core.register_abm(spec) -- Add to core.registered_abms - core.registered_abms[#core.registered_abms+1] = spec + core.registered_abms[#core.registered_abms + 1] = spec spec.mod_origin = core.get_current_modname() or "??" end @@ -391,7 +391,7 @@ end local function make_registration() local t = {} local registerfunc = function(func) - table.insert(t, func) + t[#t + 1] = func core.callback_origins[func] = { mod = core.get_current_modname() or "??", name = debug.getinfo(1, "n").name or "??" @@ -467,9 +467,9 @@ end function core.register_on_player_hpchange(func, modifier) if modifier then - table.insert(core.registered_on_player_hpchanges.modifiers, func) + core.registered_on_player_hpchanges.modifiers[#core.registered_on_player_hpchanges.modifiers + 1] = func else - table.insert(core.registered_on_player_hpchanges.loggers, func) + core.registered_on_player_hpchanges.loggers[#core.registered_on_player_hpchanges.loggers + 1] = func end core.callback_origins[func] = { mod = core.get_current_modname() or "??", |