-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Optimize the RecyclableMemoryStream usage. #17006
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,12 @@ static CommonGeneratorMethods() | |
using var uncompressedStream = MemoryStreamFactory.GetStream((int)compressedStream.Length); | ||
gZip.CopyTo(uncompressedStream); | ||
|
||
return Convert.ToBase64String(uncompressedStream.GetBuffer(), 0, (int)uncompressedStream.Length); | ||
var readOnlySequence = uncompressedStream.GetReadOnlySequence(); | ||
var base64String = readOnlySequence.IsSingleSegment ? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that is necessary because the stream will do it already: https://github.com/microsoft/Microsoft.IO.RecyclableMemoryStream/blob/master/src/RecyclableMemoryStream.cs#L508 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you're right. It would only make sense if |
||
Convert.ToBase64String(readOnlySequence.FirstSpan) : | ||
Convert.ToBase64String(uncompressedStream.GetBuffer(), 0, (int)uncompressedStream.Length); | ||
|
||
return base64String; | ||
}), | ||
}; | ||
} |
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.
Didn't know about these, apparently there are a few in
EncodingExtensions
. We should check if there aren't other places where we could use these.