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

Change GetParametersNoCopy to GetParametersAsSpan and use it in a few more places #92310

Merged
merged 2 commits into from
Sep 21, 2023

Conversation

stephentoub
Copy link
Member

The internal GetParametersNoCopy avoids a defensive ParameterInfo[] copy, but it requires the callers to promise not to mutate the array. I'm changing the method to return a ReadOnlySpan<ParameterInfo>, which means a caller can't mutate it without using unsafe code, and enabling the compiler to flag any misuse. I've then used it in a few more places. We might subsequently want to consider exposing it publicly.

@ghost
Copy link

ghost commented Sep 19, 2023

Tagging subscribers to this area: @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

Issue Details

The internal GetParametersNoCopy avoids a defensive ParameterInfo[] copy, but it requires the callers to promise not to mutate the array. I'm changing the method to return a ReadOnlySpan<ParameterInfo>, which means a caller can't mutate it without using unsafe code, and enabling the compiler to flag any misuse. I've then used it in a few more places. We might subsequently want to consider exposing it publicly.

Author: stephentoub
Assignees: stephentoub
Labels:

area-System.Reflection

Milestone: -

@jkotas
Copy link
Member

jkotas commented Sep 20, 2023

Nit: GetParametersAsSpan may be more consistent with our naming convention for overloading on return value.

Existing art

public uint GetCurrentHashAsUInt32() { throw null; }

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Thanks!

… more places

The internal GetParametersNoCopy avoids a defensive ParameterInfo[] copy, but it requires the callers to promise not to mutate the array. I'm changing the method to return a `ReadOnlySpan<ParameterInfo>`, which means a caller can't mutate it without using unsafe code, and enabling the compiler to flag any misuse.  I've then used it in a few more places. We might subsequently want to consider exposing it publicly.
@stephentoub stephentoub changed the title Change GetParametersNoCopy to GetParametersSpan and use it in a few more places Change GetParametersNoCopy to GetParametersAsSpan and use it in a few more places Sep 20, 2023
@stephentoub
Copy link
Member Author

/azp list

@azure-pipelines
Copy link

CI/CD Pipelines for this repository:

@stephentoub
Copy link
Member Author

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@stephentoub
Copy link
Member Author

Both failures are known and tracked. I ran extra platforms as well, and all of those also appear to be known, with the exception of some recently added LINQ tests failing on nativeaot for which I opened an issue.

@stephentoub stephentoub merged commit c853fc1 into dotnet:main Sep 21, 2023
218 of 247 checks passed
@stephentoub stephentoub deleted the getparametersnocopy branch September 21, 2023 03:26
@ghost ghost locked as resolved and limited conversation to collaborators Oct 21, 2023
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.

3 participants