-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Enable CA1825: Avoid zero-length array allocations #13961
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
| if (times == 0 || array.Length == 0) | ||
| { | ||
| return new T[0]; // don't use Utils.EmptyArray, always return a new array | ||
| return Array.Empty<T>(); |
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.
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.
Yes, please revert and suppress. We could update only the comment.
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 will revert and suppress, but I was wondering what reason we do not to use the static empty array?
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 don't remember. Perhaps it is used in comparisons.
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.
@PaulHigin Must we always return a new instance, rather then using the static empty array?
| public object Data { get; set; } | ||
|
|
||
| internal static readonly RuntimeDefinedParameter[] EmptyParameterArray = new RuntimeDefinedParameter[0]; | ||
| internal static readonly RuntimeDefinedParameter[] EmptyParameterArray = Array.Empty<RuntimeDefinedParameter>(); |
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.
Perhaps we can inline EmptyParameterArray ?
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.
Not in the PR.
src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs
Outdated
Show resolved
Hide resolved
address @iSazonov review
src/System.Management.Automation/engine/runtime/Operations/ArrayOps.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/runtime/Operations/ArrayOps.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs
Outdated
Show resolved
Hide resolved
|
🎉 Handy links: |
https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1825
Follow-up to #9042.