From fda6cd7237cf6cdf185c4948aa96e092c6ae6d02 Mon Sep 17 00:00:00 2001 From: Justin van der Leij Date: Sat, 7 Apr 2018 00:00:54 +0200 Subject: [PATCH] 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 --- concord/component.lua | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/concord/component.lua b/concord/component.lua index eaf4f56..7e0ae2d 100644 --- a/concord/component.lua +++ b/concord/component.lua @@ -3,17 +3,14 @@ Component.__index = Component --- Creates a new Component. -- @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 -function Component.new(populate, inherit) +function Component.new(populate) local component = setmetatable({ __populate = populate, __inherit = inherit, }, Component) - if inherit then - component.__mt = {__index = component} - end + component.__mt = {__index = component} return component end @@ -23,13 +20,9 @@ end -- @return A new initialized Bag function Component:__initialize(...) if self.__populate then - local bag = {} + local bag = setmetatable({}, self.__mt) self.__populate(bag, ...) - if self.__inherit then - setmetatable(bag, self.__mt) - end - return bag end