Refactor string parameters to ReadOnlySpans
Where appropriate, ReadOnlySpan<char>
should be preferred as method parameters over default string
type.
Ideally, these methods should also have string
, char[]
, and Span<char>
overloads that delegate down to the ReadOnlySpan<char>
version.
Other overloads are possible when dealing with strings, though none natively convert to spans, so they can't be directly delegated down to the ReadOnlySpan<char>
version.
First their are the collections:
-
IList<char>
provides a count and element access. -
ICollection<char>
provides count, but no direct element access. -
IEnumerable<char>
doesn't provide a direct count or element access.
Then we have the wrapper objects:
-
StringBuilder
is seekable, can read/insert/append/removal, not line- or indent-aware. -
TextWriter
isn't seekable, only append, not line- or indent-aware. -
IndentedTextWriter
isn't seekable, only append, is indent-aware, and not line-aware. -
TextReader
isn't seekable, only read, is line-aware, not indent-aware.
Edited by Jay Jeckel