Skip to content

Commit

Permalink
Avoid creating the capture class for calls to WithExtension (#5552)
Browse files Browse the repository at this point in the history
  • Loading branch information
Erarndt authored Jan 8, 2024
1 parent 0139b89 commit ac17919
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -722,12 +722,24 @@ private static bool Exists(this Lazy<LocalPackageSourceInfo> package)

private static IEnumerable<LockFileItem> WithExtension(this IList<LockFileItem> items, string extension)
{
if (items == null)
if (items == null || items.Count == 0)
{
return Enumerable.Empty<LockFileItem>();
}

return items.Where(c => extension.Equals(Path.GetExtension(c.Path), StringComparison.OrdinalIgnoreCase));
return FilterExtensions(items, extension);

static IEnumerable<LockFileItem> FilterExtensions(IList<LockFileItem> 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)
Expand Down

0 comments on commit ac17919

Please sign in to comment.