mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-15 18:57:08 +00:00
Faster insertion into table
This commit is contained in:
parent
75db0543f3
commit
24e8b0ac1e
13 changed files with 48 additions and 45 deletions
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 "??",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue