-
Notifications
You must be signed in to change notification settings - Fork 189
Refactor inventory data sending logic #524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -340,12 +340,13 @@ function ITEM:SetData(key, value, receivers, noSave, noCheckEntity) | |
|
|
||
| local inventory = ix.item.inventories[self.invID] | ||
|
|
||
| if (receivers != false and (receivers or inventory and inventory.GetReceivers and inventory:GetReceivers() or self:GetOwner())) then | ||
| local target = receivers or inventory and inventory.GetReceivers and inventory:GetReceivers() or self:GetOwner() | ||
| if (receivers != false and target) then | ||
|
Comment on lines
+343
to
+344
|
||
| net.Start("ixInventoryData") | ||
| net.WriteUInt(self:GetID(), 32) | ||
| net.WriteString(key) | ||
| net.WriteType(value) | ||
| net.Send(receivers or inventory and inventory.GetReceivers and inventory:GetReceivers() or self:GetOwner()) | ||
| net.Send(target) | ||
| end | ||
|
|
||
| if (!noSave and ix.db) then | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
targetis computed unconditionally. In the previous code, whenreceivers == falsetheandshort-circuit prevented evaluating the receiver expression (including potentially expensiveinventory:GetReceivers()/self:GetOwner()calls). With this refactor, those calls can still happen even though networking is disabled, which is a behavior/perf change. Consider moving thetargetcomputation inside theif (receivers != false ...)block (or guard it withif receivers != false then ... end) so the expression is only evaluated when it will be used.