calculateDiffSync<Item> function
A synchronous variant of _calculateDiff
.
Implementation
List<Operation<Item>> calculateDiffSync<Item>(
List<Item> oldList,
List<Item> newList,
bool Function(Item a, Item b) areEqual,
) {
assert(Item is! ReferenceToItemOnOtherIsolate);
var row = _getInitialRow(oldList);
for (var y = 0; y < newList.length; y++) {
final nextRow = <_Sequence<Item>>[];
for (var x = 0; x <= oldList.length; x++) {
if (x == 0) {
nextRow.add(_Sequence.insert(row[0], newList[y]));
} else if (areEqual(newList[y], oldList[x - 1])) {
nextRow.add(_Sequence.unchanged(row[x - 1]));
} else if (row[x].isShorterThan(nextRow[x - 1])) {
nextRow.add(_Sequence.insert(row[x], newList[y]));
} else {
nextRow.add(_Sequence.delete(nextRow[x - 1], oldList[x - 1]));
}
}
row = nextRow;
}
return row.last.toOperations();
}