perf: eliminate boxing with lists (#901)

This commit is contained in:
Paul Pacheco 2019-06-17 02:54:43 -05:00 committed by vis2k
parent cc6e4f696d
commit 8f6d4cb22e
2 changed files with 14 additions and 15 deletions

View File

@ -338,22 +338,9 @@ public T this[int i]
get => objects[i];
set
{
bool changed = false;
if (objects[i] == null)
{
if (value == null)
return;
else
changed = true;
}
else
{
changed = !objects[i].Equals(value);
}
objects[i] = value;
if (changed)
if (!EqualityComparer<T>.Default.Equals(objects[i], value))
{
objects[i] = value;
AddOperation(Operation.OP_SET, i, value);
}
}

View File

@ -78,6 +78,18 @@ public void TestSet()
Assert.That(clientSyncList, Is.EquivalentTo(new[] { "Hello", "yay", "!" }));
}
[Test]
public void TestSetNull()
{
serverSyncList[1] = null;
SerializeDeltaTo(serverSyncList, clientSyncList);
Assert.That(clientSyncList[1], Is.EqualTo(null));
Assert.That(clientSyncList, Is.EquivalentTo(new[] { "Hello", null, "!" }));
serverSyncList[1] = "yay";
SerializeDeltaTo(serverSyncList, clientSyncList);
Assert.That(clientSyncList, Is.EquivalentTo(new[] { "Hello", "yay", "!" }));
}
[Test]
public void TestRemoveAt()
{