perf: Use RemoveAt to remove elements from lists

This commit is contained in:
Paul Pacheco 2019-10-21 02:19:58 -05:00
parent 12c5a8fdc3
commit 22b45f7a11
2 changed files with 3 additions and 13 deletions

View File

@ -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,
@ -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;
@ -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)
@ -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;
}

View File

@ -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");