protected override void DoPatch(NListPatchEntry i) { var idx = i.iFinal; var x = _target[idx]; var y = i.Patch.Apply(x); if (!ReferenceEquals(x, y)) { _target[idx] = y; } }
void Add(NListPatchEntry entry) { if (_tail != null) { _tail.Next = entry; } else { _head = entry; } _tail = entry; }
protected override void DoPatch(NListPatchEntry i) { var idx = i.iFinal; var x = _target[idx]; var y = (UIElement)i.Patch.Apply(x); if (!ReferenceEquals(x, y)) { #if WPF _target.RemoveAt(idx); _target.Insert(idx, y); #else _target[idx] = y; #endif } }
protected override void DoMove(NListPatchEntry i) { var idx = i.iRemove; var x = _target[idx]; _target.RemoveAt(idx); var p = i.Patch; if (p != null) { x = (UIElement)p.Apply(x); } _target.Insert(i.iInsert, x); }
public void Run(NListPatchEntry head) { for (var i = head; i != null; i = i.Next) { switch (i.Op) { case NListPatchOp.Insert: DoInsert(i); break; case NListPatchOp.Remove: DoRemove(i); break; case NListPatchOp.Patch: DoPatch(i); break; case NListPatchOp.Move: DoMove(i); break; } NPatch.Finalize(i.Finalizer); } }
void OptimizeRemove(NListPatchEntry e) { var delta = 0; var oldE = e.Finalizer; var last = e; for (var i = e.Next; i != null; i = i.Next) { switch (i.Op) { case NListPatchOp.Insert: { var newE = i.Value; if (NPatch.ElementEquals(newE, oldE)) { e.Op = NListPatchOp.Move; // transform to move e.Finalizer = null; // remove finalizer e.iInsert = i.iInsert + delta; // correct insert index at the time of move e.iFinal = i.iFinal; // preserve final index e.Patch = NPropDiffer.Diff(oldE, ref newE); // make patch e.Value = oldE; // preserve moved value last.Next = i.Next; // delete insertion return; } delta--; } break; case NListPatchOp.Remove: delta++; break; } last = i; } }
internal NListPatch(NListPatchEntry head) { _head = head; }
protected override void DoRemove(NListPatchEntry i) { _target.RemoveAt(i.iRemove); }
protected override void DoInsert(NListPatchEntry i) { _target.Insert(i.iInsert, (UIElement)i.Value.Create()); }
protected abstract void DoMove(NListPatchEntry i);
protected abstract void DoPatch(NListPatchEntry i);
protected abstract void DoInsert(NListPatchEntry i);