Open
Conversation
Replace two-step [array]\ = ...; [array]\ += ... pattern with a single array concatenation expression in both the ESC3 case and the All case of Invoke-Scans. This eliminates the unnecessary intermediate array allocation and copy that occurs when += is used to append a second scan result array to the first. No behavior change: the resulting \ array contains exactly the same elements in the same order (ESC3C1 results followed by ESC3C2 results). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Optimizes (intended) the ESC3 scan result accumulation in Invoke-Scans.ps1 by replacing a two-step array build (= then +=) with a single expression, targeting reduced overhead in large AD environments.
Changes:
- Updated the
ESC3switch case to build$ESC3using a single concatenation expression. - Updated the
Allswitch case to build$ESC3using the same pattern for consistency.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace @(A) + @(B) with @(A; B) multi-statement form to avoid creating 3 intermediate arrays. The @() + @() pattern materializes both arrays separately and then allocates a third via the + operator. The single-subexpression form @(stmt1; stmt2) collects all pipeline output in one pass using PowerShell's internal List-based collector, reducing from 3 allocations to 1. Addresses GitHub Copilot code review on PR #275. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Summary
Eliminates an unnecessary intermediate array allocation in the ESC3 scan path of
Invoke-Scans.ps1.Problem
$ESC3was built with a two-step pattern:The
+=on a typed[array]forces PowerShell to allocate a new array and copy all existing elements from both sides. When ESC3C1/ESC3C2 return large result sets (common in large AD environments), this creates an avoidable O(n) copy.Fix
Combine both
Find-ESC3C*calls into a single array-concatenation expression, producing the combined array in one allocation:This change is applied in both the
ESC3case and theAllcase of theswitchblock.Scope
Private/Invoke-Scans.ps1only — two symmetric edits (ESC3 case + All case).+=usages are low-volume (bounded small arrays), string/integer arithmetic, or one-shot operations — left as-is per the task scope.Invoke-Locksmith.ps1— this is a build artifact generated byBuild-Module.ps1; source changes will be incorporated on next build.$ESC3contains the same elements in the same order (ESC3C1 results followed by ESC3C2 results).Validation