From 719f29d56cf1c84d35ca508dc9ab500aef418222 Mon Sep 17 00:00:00 2001 From: Eric Arndt Date: Mon, 11 Dec 2023 16:02:44 -0800 Subject: [PATCH] Avoid creating the capture class for calls to WithExtension --- .../RestoreCommand/Utility/BuildAssetsUtils.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/BuildAssetsUtils.cs b/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/BuildAssetsUtils.cs index 9de48fec63a..7b597c90937 100644 --- a/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/BuildAssetsUtils.cs +++ b/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/BuildAssetsUtils.cs @@ -722,12 +722,24 @@ private static bool Exists(this Lazy package) private static IEnumerable WithExtension(this IList items, string extension) { - if (items == null) + if (items == null || items.Count == 0) { return Enumerable.Empty(); } - return items.Where(c => extension.Equals(Path.GetExtension(c.Path), StringComparison.OrdinalIgnoreCase)); + return FilterExtensions(items, extension); + + static IEnumerable FilterExtensions(IList items, string extension) + { + for (int i = 0; i < items.Count; ++i) + { + var item = items[i]; + if (extension.Equals(Path.GetExtension(item.Path), StringComparison.OrdinalIgnoreCase)) + { + yield return item; + } + } + } } private static string GetMatchingFrameworkStrings(PackageSpec spec, NuGetFramework framework)