-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Use ReadOnlySpan<byte> instead of byte arrays #35125
Use ReadOnlySpan<byte> instead of byte arrays #35125
Conversation
@stephentoub, do we have an issue for an analyzer for this and |
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.
One cleanup comment, but otherwise LGTM.
SafeProvHandle hProv, | ||
byte[] pbData, | ||
ReadOnlySpan<byte> pbData, | ||
int dwDataLen, |
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.
Since we're taking spans instead of entire arrays, does it make sense to clean up this call site by removing the dwDataLen parameter and inferring the value from the span length?
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.
Seems reasonable; so changed. The callers of this always passed in array.Length
anyway.
Not yet implemented, but it's on our list: #33780 |
// Windows compat. | ||
if (s_invalidEmptyOid.AsSpan().SequenceEqual(encodedOid)) | ||
if (invalidEmptyOid.SequenceEqual(encodedOid)) |
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.
Would it be better to just do:
if (encodedOid?.Length == 2 && encodedOid[0] == 6 && encodedOid[1] == 0)
?
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.
Also a good idea. I changed the method's parameter from byte[]
to ReadOnlySpan<byte>
to remove the need for the null check and switched to AsnValueReader
. The only caller of this method is here
Lines 48 to 51 in 2d1f7b0
if (rawData == null) | |
return null; | |
string contentTypeValue = PkcsHelpers.DecodeOid(rawData); |
And already did the null check, so the implicit conversion doesn't come in to play.
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.
I also considered making a similar change to pSpecifiedDefaultParameters
but since it is a negative condition it seemed to make things less readable.
One CI leg appears to be stalled - even on rerun. Not worried about it. |
A few more changes to use the compiler's
ReadOnlySpan<byte>
optimization trick instead of static byte arrays.