-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix most violations of new CA1859 #80335
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
Conversation
Tagging subscribers to this area: @dotnet/area-meta Issue DetailsThe analyzer recommends replacing uses of types with other types that could reduce overheads (e.g.
|
Wow, that's a lot of stuff. CA1859 currently only recommends changing the signature of private methods and fields, the idea being that the changes are completely local to a given type. Do you think it would be useful to extend the analysis to internal symbols too, at least optionally? I bet that would raise another crop of these recommendations. Another thing I'd like to add in the analyzer is a basic understanding of collections. So if you have an |
The analyzer recommends replacing uses of types with other types that could reduce overheads (e.g. `List<T>` instead of `IList<T>`). This fixes most of the violations we currently have of the rule, but it doesn't enable it yet because there are too many false positives; fixes for those are in-flight. Some of these replacements won't help with perf (e.g. using `ArgumentException` instead of `Exception` as the return type of a throw helper create method), but there's little harm to them, and some of them do avoid overheads like allocation (e.g. foreach'ing something typed as `Dictionary<>` instead of `IDictionary<>` will avoid an enumerator allocation, accessing `Count` on a `List<T>` instead of `IList<T>` will avoid an interface dispatch, etc.)
Can you share an example?
Yeah, I think that would be useful, at least for some of the most common, like IEnumerable and List. |
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.
Left a few NITs, overall LGTM, thank you!
src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Error.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpRequestStream.Windows.cs
Show resolved
Hide resolved
...m.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509Pal.OpenSsl.cs
Show resolved
Hide resolved
Be gone Peanut Butter! |
The analyzer recommends replacing uses of types with other types that could reduce overheads (e.g.
List<T>
instead ofIList<T>
). This fixes most of the violations we currently have of the rule, but it doesn't enable it yet because there are too many false positives; fixes for those are in-flight. Some of these replacements won't help with perf (e.g. usingArgumentException
instead ofException
as the return type of a throw helper create method), but there's little harm to them, and some of them do avoid overheads like allocation (e.g. foreach'ing something typed asDictionary<>
instead ofIDictionary<>
will avoid an enumerator allocation, accessingCount
on aList<T>
instead ofIList<T>
will avoid an interface dispatch, etc.)cc: @buyaa-n, @geeknoid