You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
API Proposal: SequenceReader<T>.TryPeek overloads for look ahead #30771
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.
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).
Are we fine with having to incur the cost of slicing the sequence and fetching the span again (for the API that takes a SequencePosition)? The other existing APIs on SequenceReader do not have this overhead. This concern would apply to all the APIs that take an arbitrary SequencePosition.
Activity
JeremyKuhne commentedon Sep 6, 2019
I think a better choice here would be:
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.
softworkz commentedon Sep 6, 2019
You mean that this method should actually advance the reader?
JeremyKuhne commentedon Sep 6, 2019
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).
softworkz commentedon Sep 6, 2019
Ah ok. So what are you implying by changing:
bool TryPeek(int count, out T value);to
bool TryPeek(int skip, out T value);Was it just about a better parameter naming then?
JeremyKuhne commentedon Sep 6, 2019
Yep.
softworkz commentedon Sep 6, 2019
I apologize - I misunderstood.
ahsonkhan commentedon Sep 9, 2019
Are we fine with having to incur the cost of slicing the sequence and fetching the span again (for the API that takes a
SequencePosition)? The other existing APIs onSequenceReaderdo not have this overhead. This concern would apply to all the APIs that take an arbitrarySequencePosition.Maybe, something like this:
JeremyKuhne commentedon Sep 10, 2019
Video
Approved: dotnet/corefx#40962 (comment):
ahsonkhan commentedon Sep 11, 2019
@JeremyKuhne - the parameter name isn't
skip. It should beoffset.Also, don't forget the
readonlykeyword (+ the comment link needs to be updated).JeremyKuhne commentedon Sep 11, 2019
Copy/paste fail. Fixing.