Skip to content
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

Add Memory Overrides to Streams #47125

Merged

Conversation

NewellClark
Copy link
Contributor

@NewellClark NewellClark commented Jan 18, 2021

In the process of implementing Override Stream ReadAsync/WriteAsync, I ran the analyzer against dotnet/runtime and found 7 violations. This is one of them.
I've added the required memory-based overrides, and refactored it so the array-based overrides are implemented in terms of the memory-based overrides. In order to do this, I had to add an overload of Inflater.SetBuffer that accepts memory. Same thing here; I refactored the array-based SetInput to delegate to the new memory-based overload.

I've also fixed RequestStream, ChunkedMemoryStream, and NetworkStreamWrapper, which were all trivial fixes.

Should I do a separate PR for every violation I fix, or fix them all in one PR? Some of the fixes are non-trivial, and would require adding overloads to multiple dependencies used by the violating stream, which is why I figured a separate PR would be in order for each one.

Edit: to clarify, this is the PR I'm using for all the streams that are trivial to update. I'll be doing separate PRs for the streams that are not trivial to update.

-Implemented memory-based WriteAsync in DeflateStream.CopyToStream class.

This required implementing a memory-based overload of System.IO.Inflater.SetInput(). Previously, Inflater used a GCHandle to pin the array that was passed into SetInput. I converted it to use a MemoryHandle, and changed the array-based overload of SetInput to delegate to the new Memory-based overload.
Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this.

@stephentoub
Copy link
Member

Should I do a separate PR for every violation I fix, or fix them all in one PR?

In particular for any that are controversial or non-trivial, one per PR is good.

For the rest, you can batch them up.

- Memory overrides for System.Net.RequestStream
- Memory overrides for System.Net.NetworkStreamWrapper
WriteAsync is implemented in terms of Write, so I went ahead and implemented Write(ReadOnlySpan<byte>). 
For some reason, AsSpan() isn't available in this file.
@NewellClark NewellClark changed the title System.IO.Compression.DeflateStream.CopyToStream Add Memory Overrides to Streams Jan 21, 2021
Base automatically changed from master to main March 1, 2021 09:07
Copy link
Member

@carlossanlop carlossanlop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Triage: Reviewed with @adamsitnik and @jozkee and it looks good.
Suggestions have been addressed and CI is passing.

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @NewellClark !

@adamsitnik adamsitnik merged commit 62f6c08 into dotnet:main Mar 5, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Apr 4, 2021
@karelz karelz added this to the 6.0.0 milestone May 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants