preprocessListDiff<T> function

ListDiffs<T>? preprocessListDiff<T>(
  1. ListDiffArguments<T> args
)

Looks for empty lists, which may signal an easier diff operation

Implementation

ListDiffs<T>? preprocessListDiff<T>(ListDiffArguments<T> args) {
  final oldIsEmpty = args.original.isEmpty;
  final newIsEmpty = args.replacement.isEmpty;

  if (oldIsEmpty && newIsEmpty) {
    return ListDiffs<T>.empty(args);
  }

  if (oldIsEmpty) {
    return ListDiffs.ofOperations(
        [InsertDiff(args, 0, args.original.length, args.replacement)], args);
  }

  if (newIsEmpty) {
    return ListDiffs.ofOperations(
        [DeleteDiff(args, 0, args.original.length)], args);
  }

  return null;
}