-
Notifications
You must be signed in to change notification settings - Fork 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
Use ReadOnlySpan properties over array fields #56845
Use ReadOnlySpan properties over array fields #56845
Conversation
There are likely similar hits in the non-compiler layers. If so, can you make a PR for that as well (independent of this one)? I'd be happy to review it and get it in asap for the higher layers. |
I ran the analyzer on the entire dotnet/roslyn repository, not just the projects in the Compiler folder. I think the bot mislabeled this PR. |
THe bot is correct here (since you only touched the compiler layer). I am surprised though as i'm sure we have read-only arrays at the IDE layer that could benefit from this. For example:
|
At the moment, the analyzer only reports arrays for |
Ah. I'd like this not for any sort of optimization, but just for general safety. Those arrays should be immutable or ROS's so that no one can accidentally change their contents. |
@CyrusNajmabadi It may be a good idea to create a separate rule that finds all static readonly array fields or auto-properties that are never mutated and suggests converting them to |
Tagging @mavasani I think it would be great to have that. If he agrees then I think roslyn-analyzers would be the right place. |
src/Compilers/Core/CodeAnalysisTest/PEWriter/InstructionOperandTypesTests.cs
Outdated
Show resolved
Hide resolved
@RikkiGibson, @chsienki PTAL |
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.
LGTM, you can resolve the nit or not at your discretion and let us know when the PR is ready for merge.
/azp run |
Azure Pipelines successfully started running 4 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 4 pipeline(s). |
Thanks for the contribution @NewellClark! |
While working on this analyzer I found and fixed several violations in dotnet/roslyn.