Skip to content

Commit fcccc92

Browse files
committed
optimize event
caching micro optimization remove unused code demote fix_args behind a string comparison check
1 parent 487f700 commit fcccc92

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

lua/pac3/core/client/parts/event.lua

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3668,11 +3668,12 @@ PART.last_event_triggered = false
36683668

36693669
function PART:fix_args()
36703670
local args = string.Split(self.Arguments, "@@")
3671-
if self.Events[self.Event] then
3672-
if self.Events[self.Event].__registeredArguments then
3671+
local event_data = self.Events[self.Event] --caching to save on index calls
3672+
if event_data then
3673+
if event_data.__registeredArguments then
36733674
--PrintTable(self.Events[self.Event].__registeredArguments)
3674-
if #self.Events[self.Event].__registeredArguments ~= #args then
3675-
for argn,arg in ipairs(self.Events[self.Event].__registeredArguments) do
3675+
if #event_data.__registeredArguments ~= #args then
3676+
for argn,arg in ipairs(event_data.__registeredArguments) do
36763677
if not args[argn] or args[argn] == "" then
36773678
local added_arg = "0"
36783679
if arg[2] == "boolean" then
@@ -3694,13 +3695,10 @@ function PART:fix_args()
36943695
end
36953696
end
36963697
end
3698+
self.fixed_args = self.Arguments
36973699
end
36983700

36993701
function PART:OnThink()
3700-
self.nextactivationrefresh = self.nextactivationrefresh or CurTime()
3701-
if not self.singleactivatestate and self.nextactivationrefresh < CurTime() then
3702-
self.singleactivatestate = true
3703-
end
37043702

37053703
local ent = get_owner(self)
37063704
if not ent:IsValid() then return end
@@ -3709,7 +3707,7 @@ function PART:OnThink()
37093707

37103708
if not data then return end
37113709

3712-
self:fix_args()
3710+
if self.fixed_args ~= self.Arguments then self:fix_args() end
37133711
self:TriggerEvent(should_trigger(self, ent, data))
37143712

37153713
if pace and pace.IsActive() and self.Name == "" then
@@ -3985,7 +3983,6 @@ function PART:OnShow()
39853983
self.number = 0
39863984
end
39873985
self.showtime = CurTime()
3988-
self.singleactivatestate = true
39893986
end
39903987

39913988
function PART:OnAnimationEvent(ent)

0 commit comments

Comments
 (0)