Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid creating the capture class for calls to WithExtension #5552

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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