Skip to content

Commit

Permalink
perf: eliminate small allocation on remote calls (#907)
Browse files Browse the repository at this point in the history
* perf: eliminate small allocation on remote calls

* Update NetworkBehaviour.cs
  • Loading branch information
paulpach authored and miwarnec committed Jun 17, 2019
1 parent 8f6d4cb commit 1c18743
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Assets/Mirror/Runtime/NetworkBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@ public int ComponentIndex
{
get
{
int index = Array.FindIndex(netIdentity.NetworkBehaviours, component => component == this);
if (index < 0)
// note: FindIndex causes allocations, we search manually instead
for (int i = 0; i < netIdentity.NetworkBehaviours.Length; i++)
{
// this should never happen
Debug.LogError("Could not find component in GameObject. You should not add/remove components in networked objects dynamically", this);
NetworkBehaviour component = netIdentity.NetworkBehaviours[i];
if (component == this)
return i;
}

return index;
// this should never happen
Debug.LogError("Could not find component in GameObject. You should not add/remove components in networked objects dynamically", this);

return -1;
}
}

Expand Down

0 comments on commit 1c18743

Please sign in to comment.