Skip to content

Commit

Permalink
perf: Use RemoveAt to remove elements from lists
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpach committed Oct 21, 2019
1 parent 12c5a8f commit 22b45f7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
14 changes: 2 additions & 12 deletions Assets/Mirror/Runtime/SyncList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public enum Operation : byte
OP_ADD,
OP_CLEAR,
OP_INSERT,
[Obsolete("Lists now pass OP_REMOVEAT")]
OP_REMOVE,
OP_REMOVEAT,
OP_SET,
Expand Down Expand Up @@ -155,7 +156,6 @@ public void OnSerializeDelta(NetworkWriter writer)
switch (change.operation)
{
case Operation.OP_ADD:
case Operation.OP_REMOVE:
SerializeItem(writer, change.item);
break;

Expand Down Expand Up @@ -243,15 +243,6 @@ public void OnDeserializeDelta(NetworkReader reader)
}
break;

case Operation.OP_REMOVE:
item = DeserializeItem(reader);
index = IndexOf(item);
if (apply)
{
objects.RemoveAt(index);
}
break;

case Operation.OP_REMOVEAT:
index = (int)reader.ReadPackedUInt32();
if (apply)
Expand Down Expand Up @@ -328,8 +319,7 @@ public bool Remove(T item)
bool result = index >= 0;
if (result)
{
objects.RemoveAt(index);
AddOperation(Operation.OP_REMOVE, 0, item);
RemoveAt(index);
}
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirror/Tests/SyncListTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void CallbackRemoveTest()
{
called = true;
Assert.That(op, Is.EqualTo(SyncList<string>.Operation.OP_REMOVE));
Assert.That(op, Is.EqualTo(SyncList<string>.Operation.OP_REMOVEAT));
Assert.That(item, Is.EqualTo("World"));
};
serverSyncList.Remove("World");
Expand Down

0 comments on commit 22b45f7

Please sign in to comment.