mirror of
https://github.com/kikito/middleclass.git
synced 2024-11-08 09:34:22 +00:00
reduce a conditional branch in wrapped __index function
This commit is contained in:
parent
fd25b1a006
commit
63f83ea0ef
@ -31,14 +31,22 @@ local middleclass = {
|
|||||||
local function _createIndexWrapper(aClass, f)
|
local function _createIndexWrapper(aClass, f)
|
||||||
if f == nil then
|
if f == nil then
|
||||||
return aClass.__instanceDict
|
return aClass.__instanceDict
|
||||||
else
|
elseif type(f) == "function" then
|
||||||
return function(self, name)
|
return function(self, name)
|
||||||
local value = aClass.__instanceDict[name]
|
local value = aClass.__instanceDict[name]
|
||||||
|
|
||||||
if value ~= nil then
|
if value ~= nil then
|
||||||
return value
|
return value
|
||||||
elseif type(f) == "function" then
|
else
|
||||||
return (f(self, name))
|
return (f(self, name))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else -- if type(f) == "table" then
|
||||||
|
return function(self, name)
|
||||||
|
local value = aClass.__instanceDict[name]
|
||||||
|
|
||||||
|
if value ~= nil then
|
||||||
|
return value
|
||||||
else
|
else
|
||||||
return f[name]
|
return f[name]
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user