Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Stream wrappers for memory and text-based types #126669
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
base: main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Add Stream wrappers for memory and text-based types #126669
Changes from all commits
1f1bfe1f7a06f0bd5cf98fec7a59341ad578882b050fb2ef5File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ref is only including overrides for the abstract members whereas the other refs later are also including overrides for the virtual members?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad. I'll verify it with GenAPI. Thanks :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: would it be better if you override CopyTo/CopyToAsyn? a direct implementation could iterate segments via ReadOnlySequence.GetEnumerator() and write each segment directly, much more efficient for multi-segment sequences. The base one reads in generic 81920-byte chunks which can be less efficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReadOnlySequenceStream.Position computes the current offset via
_sequence.Slice(_sequence.Start, _position).Lengtheach time. On multi-segment sequences this is O(segments) per call and can become very expensive (e.g., SeekOrigin.Current / Position-heavy loops). Consider tracking a numeric position field updated on Read/Seek/Position set, using SequencePosition only as an iterator cursor.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to override
ReadBytetoo for the sake of the perf. Otherwise, it will fall back to Stream.ReadByte() which allocates anew byte[1]on every call. All three other stream types in this PR overrideReadByte()for performance. This should have one too.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Position = -1will throw an ArgumentOutOfRangeException butSeek(-1, SeekOrigin.Begin)will throw an IOException. Is that consistent with what we do in other Stream types?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per
MemoryStreamandUnmanagedMemoryStream, it is: In both, Position setter throwsArgumentOutOfRangeExceptionfor negatives, while Seek throwsIOException.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: both Position setter and Seek call
_sequence.GetPosition(value, _sequence.Start)which walks from the start of the sequence every time. For a 1000-segment sequence, seeking from position 999 to 1000 walks all 1000 segments. Should use relative positioning from _position when possible (advancing forward by value - _absolutePosition)?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to add
_sequence = default? to remove any references to underlying buffers?Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.