You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As some of the below articles note, using += with an Array object can be very slow, as it copies the Array into a new Array in-memory. The recommendation is very often to use List objects instead of Arrays to avoid this problem.
When used in a loop, it's probably a good idea. Otherwise, it may be annoying because there are many reasonable applications of += that may be even faster or just cleaner. New-Object System.Collections.Generic.List[System.Object] is quite an expression to type, parse, evaluate.
Good idea in general but I also agree with @nightroman that one does not care in most situations. I think it would make sense to group PSScriptAnalyzer warnings into something like 3 categories so that one can either configure PSScriptanalyzer to apply only rules of those categories or alternatively filter for them later on:
CodeAnalysis (where stuff can go wrong like e.g. PSPossibleIncorrectComparisonWithNull)
Best Practices (e.g. PSUseShouldProcessForStateChangingFunctions)
As some of the below articles note, using
+=
with an Array object can be very slow, as it copies the Array into a new Array in-memory. The recommendation is very often to use List objects instead of Arrays to avoid this problem.Thoughts?
https://stackoverflow.com/questions/14620290/powershell-array-add-vs
https://powershell.org/2013/09/16/powershell-performance-the-operator-and-when-to-avoid-it/
The text was updated successfully, but these errors were encountered: