Enable CA1825: Avoid zero-length array allocations - #13961
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.
Ilya (@iSazonov) Perhaps we should suppress CA1825 here, if there is still a rationale for always returning a new array instance. Utils.EmptyArray was removed in your PR #9042.
There was a problem hiding this comment.
Yes, please revert and suppress. We could update only the comment.
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?
There was a problem hiding this comment.
I don't remember. Perhaps it is used in comparisons.
There was a problem hiding this comment.
Paul Higinbotham (@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.
Perhaps we can inline EmptyParameterArray ?
address @iSazonov review
|
🎉 Handy links: |
https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1825
Follow-up to #9042.