Skip to content

API: accept IReadOnlyList<T> for read-only inputs (CalculateSections / AlignElements) #25

Description

@lassevk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions