Skip to content

Commit 6f7f2c8

Browse files
authored
Micro-optimization for E2Lib.IsOwner (#3162)
Remove the singleplayer check and just define the function right away
1 parent 1857174 commit 6f7f2c8

File tree

1 file changed

+11
-6
lines changed
  • lua/entities/gmod_wire_expression2/core

1 file changed

+11
-6
lines changed

lua/entities/gmod_wire_expression2/core/e2lib.lua

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,17 @@ function E2Lib.isFriend(owner, player)
466466
return owner == player
467467
end
468468

469-
function E2Lib.isOwner(self, entity)
470-
if game.SinglePlayer() then return true end
471-
local owner = E2Lib.getOwner(self, entity)
472-
if not IsValid(owner) then return false end
473-
474-
return E2Lib.isFriend(owner, self.player)
469+
if game.SinglePlayer() then
470+
function E2Lib.isOwner(self, entity)
471+
return true
472+
end
473+
else
474+
function E2Lib.isOwner(self, entity)
475+
local owner = E2Lib.getOwner(self, entity)
476+
if not IsValid(owner) then return false end
477+
478+
return E2Lib.isFriend(owner, self.player)
479+
end
475480
end
476481

477482
local isOwner = E2Lib.isOwner

0 commit comments

Comments
 (0)