From 20e6b1201c821d3cea4e177475881aa5e19123f4 Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Sat, 5 Dec 2020 12:07:20 +0000 Subject: [PATCH] Avoid array allocations from GetDirectories/GetFiles. Contributes to PowerShell#14318. --- .../engine/Modules/AnalysisCache.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/Modules/AnalysisCache.cs b/src/System.Management.Automation/engine/Modules/AnalysisCache.cs index 8b055d8fb0f..745f245f8f0 100644 --- a/src/System.Management.Automation/engine/Modules/AnalysisCache.cs +++ b/src/System.Management.Automation/engine/Modules/AnalysisCache.cs @@ -371,7 +371,7 @@ private static ConcurrentDictionary AnalyzeScriptModule(st try { - foreach (string item in Directory.GetFiles(baseDirectory, "*.ps1")) + foreach (string item in Directory.EnumerateFiles(baseDirectory, "*.ps1")) { var command = Path.GetFileNameWithoutExtension(item); result.AddOrUpdate(command, CommandTypes.ExternalScript,