Skip to content

Commit

Permalink
Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
Denneisk committed Nov 11, 2023
1 parent 2cb57ef commit c22a21c
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions lua/entities/gmod_wire_expression2/core/selfaware.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,26 +206,29 @@ end
--[[******************************************************************************]]--
-- Extensions

local getExtensionStatus = E2Lib.GetExtensionStatus
local e2Extensions
local e2ExtensionsTable
-- See postinit for these getting initialized

[nodiscard]
e2function array getExtensions()
return table.Copy(E2Lib.GetExtensions())
local ret = {}
for k, v in ipairs(e2Extensions) do -- Optimized shallow copy
ret[k] = v
end
return ret
end

local getExtensionStatus = E2Lib.GetExtensionStatus
__e2setcost(10)

[nodiscard]
e2function table getExtensionStatus()
local ret = E2Lib.newE2Table()
local s, stypes, size = ret.s, ret.stypes, ret.size
for _, ext in ipairs(E2Lib.GetExtensions()) do
s[ext] = getExtensionStatus(ext) and 1 or 0
stypes[ext] = "n"
size = size + 1
end
ret.s, ret.stypes, ret.size = s, stypes, size -- Do this just because I'm paranoid

return ret
return table.Copy(e2ExtensionsTable)
end

__e2setcost(5)

[nodiscard]
e2function number getExtensionStatus(string extension)
return getExtensionStatus(extension) and 1 or 0
Expand Down Expand Up @@ -315,6 +318,18 @@ registerCallback("postinit", function()
end
end
end

e2Extensions = E2Lib.GetExtensions()
e2ExtensionsTable = E2Lib.newE2Table()
do
local s, stypes, size = e2ExtensionsTable.s, e2ExtensionsTable.stypes, 0
for _, ext in ipairs(e2Extensions) do
s[ext] = getExtensionStatus(ext) and 1 or 0
stypes[ext] = "n"
size = size + 1
end
e2ExtensionsTable.size = size
end
end)

--[[******************************************************************************]]--
Expand Down

0 comments on commit c22a21c

Please sign in to comment.