Enable CA1825: Avoid zero-length array allocations#13961
Merged
iSazonov merged 7 commits intoPowerShell:masterfrom Nov 4, 2020
Merged
Enable CA1825: Avoid zero-length array allocations#13961iSazonov merged 7 commits intoPowerShell:masterfrom
iSazonov merged 7 commits intoPowerShell:masterfrom
Conversation
xtqqczze
commented
Nov 1, 2020
| if (times == 0 || array.Length == 0) | ||
| { | ||
| return new T[0]; // don't use Utils.EmptyArray, always return a new array | ||
| return Array.Empty<T>(); |
Contributor
Author
Collaborator
There was a problem hiding this comment.
Yes, please revert and suppress. We could update only the comment.
Contributor
Author
There was a problem hiding this comment.
I will revert and suppress, but I was wondering what reason we do not to use the static empty array?
Collaborator
There was a problem hiding this comment.
I don't remember. Perhaps it is used in comparisons.
Contributor
Author
There was a problem hiding this comment.
@PaulHigin Must we always return a new instance, rather then using the static empty array?
xtqqczze
commented
Nov 1, 2020
xtqqczze
commented
Nov 1, 2020
| public object Data { get; set; } | ||
|
|
||
| internal static readonly RuntimeDefinedParameter[] EmptyParameterArray = new RuntimeDefinedParameter[0]; | ||
| internal static readonly RuntimeDefinedParameter[] EmptyParameterArray = Array.Empty<RuntimeDefinedParameter>(); |
Contributor
Author
There was a problem hiding this comment.
Perhaps we can inline EmptyParameterArray ?
iSazonov
reviewed
Nov 2, 2020
src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs
Outdated
Show resolved
Hide resolved
address @iSazonov review
iSazonov
reviewed
Nov 2, 2020
src/System.Management.Automation/engine/runtime/Operations/ArrayOps.cs
Outdated
Show resolved
Hide resolved
iSazonov
reviewed
Nov 2, 2020
src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs
Outdated
Show resolved
Hide resolved
iSazonov
reviewed
Nov 2, 2020
src/System.Management.Automation/engine/runtime/Operations/ArrayOps.cs
Outdated
Show resolved
Hide resolved
iSazonov
reviewed
Nov 2, 2020
src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs
Outdated
Show resolved
Hide resolved
iSazonov
approved these changes
Nov 2, 2020
PaulHigin
approved these changes
Nov 3, 2020
|
🎉 Handy links: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1825
Follow-up to #9042.