Diff.CalculateSections, Diff.AlignElements, and the IDiffElementAligner<T>.Align surface all take IList<T?>, but they only ever read from the collections (indexer + Count). Requiring IList<T> forces callers who hold read-only collections (ImmutableArray<T>, IReadOnlyList<T>-returning APIs, arrays exposed as read-only, etc.) to copy into a List/array first.
MutateToBeLike genuinely needs IList<T> (it mutates target) and should stay as-is. But everything on the pure-diff path could take IReadOnlyList<T?>.
Options:
- Add
IReadOnlyList<T?> overloads alongside the existing IList<T?> ones (additive, but introduces overload-resolution ambiguity for types implementing both — arrays/List<T>).
- Or introduce a small internal read-only view abstraction and route both through it.
This also sets up the span/memory work (see the modernization issue) since a read-only, index-based contract is the natural seam for it.
Note: string implements neither IList<char> nor IReadOnlyList<char>, so string diffing still needs ToCharArray() today — that part is addressed by the span/allocation issue.
Diff.CalculateSections,Diff.AlignElements, and theIDiffElementAligner<T>.Alignsurface all takeIList<T?>, but they only ever read from the collections (indexer +Count). RequiringIList<T>forces callers who hold read-only collections (ImmutableArray<T>,IReadOnlyList<T>-returning APIs, arrays exposed as read-only, etc.) to copy into aList/array first.MutateToBeLikegenuinely needsIList<T>(it mutatestarget) and should stay as-is. But everything on the pure-diff path could takeIReadOnlyList<T?>.Options:
IReadOnlyList<T?>overloads alongside the existingIList<T?>ones (additive, but introduces overload-resolution ambiguity for types implementing both — arrays/List<T>).This also sets up the span/memory work (see the modernization issue) since a read-only, index-based contract is the natural seam for it.
Note:
stringimplements neitherIList<char>norIReadOnlyList<char>, so string diffing still needsToCharArray()today — that part is addressed by the span/allocation issue.