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<T>.TryPeek overloads for look ahead #30771
Comments
I think a better choice here would be: public partial ref struct SequenceReader<T>
{
bool TryPeek(int skip, out T value);
} Picking an arbitrary start position makes the reader confusing- it has a position and is mostly forward-only. In addition the perf characteristics would be way out of line with the related methods. |
You mean that this method should actually advance the reader? |
No, the peek methods shouldn't advance the reader at all. The idea here is that you can peek ahead for a value without having to get a set of values or rewinding the reader. Say, peek for a CR then peek again for a LF, rather than a CR/LF (as a simple example). |
Ah ok. So what are you implying by changing:
to
Was it just about a better parameter naming then? |
Yep. |
I apologize - I misunderstood. |
Are we fine with having to incur the cost of slicing the sequence and fetching the span again (for the API that takes a Maybe, something like this: public readonly bool TryPeek(SequencePosition position, out T value)
{
ReadOnlySequence<T> sequence = Sequence.Slice(position);
ReadOnlySpan<T> span = sequence.FirstSpan;
if (!span.IsEmpty)
{
value = span[0];
return true;
}
else
{
value = default;
return false;
}
} |
Approved: dotnet/corefx#40962 (comment): public readonly bool TryPeek(long offset, out T value); |
@JeremyKuhne - the parameter name isn't Also, don't forget the |
Copy/paste fail. Fixing. |
Today it isn't easy to get the value at a specific position from the
ReadOnlySequence<T>
making it hard to write parsers that look ahead at data without moving the reader.cc @softworkz
The text was updated successfully, but these errors were encountered: