New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API proposal: SequenceReader.TryReadTo(out ReadOnlySpan<T> sequence, ReadOnlySpan<T> delimiter) #31355
Comments
To which type this should apply? I assume
|
@gfoidl fixed! |
We were a little pressed for time, it might have fallen off due to additional complexity to optimize that case. |
namespace System.Buffers
{
public ref struct SequenceReader<T>
{
// Existing API
// public bool TryReadTo(out ReadOnlySequence<T> sequence, T delimiter, bool advancePastDelimiter = true);
public bool TryReadTo(out ReadOnlySpan<T> span, ReadOnlySpan<T> delimiter, bool advancePastDelimiter = true);
}
} |
Uhhhhh yes we do. |
Watch the video, I kind of predicted you'd say that :-) |
Every other namespace System.Buffers
{
public ref struct SequenceReader<T>
{
// Existing api pairs: out ReadOnlySequence
public bool TryReadTo(out ReadOnlySequence<T> sequence, T delimiter, bool advancePastDelimiter = true);
public bool TryReadTo(out ReadOnlySequence<T> sequence, T delimiter, T delimiterEscape, bool advancePastDelimiter = true);
public bool TryReadToAny(out ReadOnlySequence<T> sequence, ReadOnlySpan<T> delimiters, bool advancePastDelimiter = true);
// Existing api pairs: out ReadOnlySpan
public bool TryReadTo(out ReadOnlySpan<T> span, T delimiter, bool advancePastDelimiter = true);
public bool TryReadTo(out ReadOnlySpan<T> span, T delimiter, T delimiterEscape, bool advancePastDelimiter = true);
public bool TryReadToAny(out ReadOnlySpan<T> span, ReadOnlySpan<T> delimiters, bool advancePastDelimiter = true);
// Missing pair: out ReadOnlySpan
public bool TryReadTo(out ReadOnlySequence<T> sequence, ReadOnlySpan<T> delimiter, bool advancePastDelimiter = true)
}
} QED it is a missing api and the video didn't address that and if (reader.TryReadTo(out sequence, delimiter, advancePastDelimiter: true))
{
ReadOnlySpan<T> span = sequence.IsSingleSegment ? sequence.First.Span : sequence.ToArray();
} Is way more inefficient than what the other methods do which is search the existing |
I'm going to re-open this so we can re-discuss it 😄 . As @benaadams said, the other overloads do this, we should suggest an alternative pattern if we don't like this one but we need something. |
I brought up how we rejected the ReadOnlySpan version of #30778 for this same reason reason in the chat during API review. If we go through with this API, we should look at that API again as well. I talked about my opinions on the Span returning APIs in that issue #30778 (comment) |
After much debate, approved as proposed: public partial ref struct SequenceReader
{
public bool TryReadTo(out ReadOnlySpan<T> span, ReadOnlySpan<T> delimiter, bool advancePastDelimiter = true);
} |
@bartonjs to follow up on api review, you can't mimic the behaviour with an extension method and the |
Today there's no overload of TryReadTo that returns (via out parameter) a
ReadOnlySpan<T>
and allows passing aReadOnlySpan<T>
delimeter.@JeremyKuhne do you recall why we left this out?
The text was updated successfully, but these errors were encountered: