mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
perf: Use RemoveAt to remove elements from lists
This commit is contained in:
parent
12c5a8fdc3
commit
22b45f7a11
@ -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;
|
||||
}
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user