mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-02 12:24:11 -04:00
Removed the inherit option for components. They are functional by default now
Turns out doing a 'setmetatable' only makes the code 0.00038% slower. Effectively making the previous code slower because of the branches. Who would've tought
This commit is contained in:
parent
a173de40eb
commit
fda6cd7237
1 changed files with 3 additions and 10 deletions
|
@ -3,17 +3,14 @@ Component.__index = Component
|
||||||
|
|
||||||
--- Creates a new Component.
|
--- Creates a new Component.
|
||||||
-- @param populate A function that populates the Bag with values
|
-- @param populate A function that populates the Bag with values
|
||||||
-- @param inherit States if the Bag should inherit the Component's functions
|
|
||||||
-- @return A Component object
|
-- @return A Component object
|
||||||
function Component.new(populate, inherit)
|
function Component.new(populate)
|
||||||
local component = setmetatable({
|
local component = setmetatable({
|
||||||
__populate = populate,
|
__populate = populate,
|
||||||
__inherit = inherit,
|
__inherit = inherit,
|
||||||
}, Component)
|
}, Component)
|
||||||
|
|
||||||
if inherit then
|
component.__mt = {__index = component}
|
||||||
component.__mt = {__index = component}
|
|
||||||
end
|
|
||||||
|
|
||||||
return component
|
return component
|
||||||
end
|
end
|
||||||
|
@ -23,13 +20,9 @@ end
|
||||||
-- @return A new initialized Bag
|
-- @return A new initialized Bag
|
||||||
function Component:__initialize(...)
|
function Component:__initialize(...)
|
||||||
if self.__populate then
|
if self.__populate then
|
||||||
local bag = {}
|
local bag = setmetatable({}, self.__mt)
|
||||||
self.__populate(bag, ...)
|
self.__populate(bag, ...)
|
||||||
|
|
||||||
if self.__inherit then
|
|
||||||
setmetatable(bag, self.__mt)
|
|
||||||
end
|
|
||||||
|
|
||||||
return bag
|
return bag
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue