Skip to content

Commit

Permalink
reduce a conditional branch in wrapped __index function
Browse files Browse the repository at this point in the history
  • Loading branch information
jojo59516 committed Oct 18, 2019
1 parent fd25b1a commit 63f83ea
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions middleclass.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,22 @@ local middleclass = {
local function _createIndexWrapper(aClass, f)
if f == nil then
return aClass.__instanceDict
else
elseif type(f) == "function" then
return function(self, name)
local value = aClass.__instanceDict[name]

if value ~= nil then
return value
elseif type(f) == "function" then
else
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
return f[name]
end
Expand Down

0 comments on commit 63f83ea

Please sign in to comment.