Skip to content

Commit e2cf523

Browse files
Remove LINQ from GetBySupportedCommands
1 parent 6670e04 commit e2cf523

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

src/ImageSharp.Web/Processors/WebProcessingExtensions.cs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,33 @@ public static FormattedImage Process(
5454
/// The sorted proccessors that supports any of the specified commands.
5555
/// </returns>
5656
public static IEnumerable<IImageWebProcessor> GetBySupportedCommands(this IEnumerable<IImageWebProcessor> processors, List<string> commands)
57-
=> processors
58-
.GroupBy(p => commands.FindIndex(c => p.Commands.Contains(c, StringComparer.OrdinalIgnoreCase))) // Get index of first supported command
59-
.Where(g => g.Key != -1) // Filter processors without supported commands
60-
.OrderBy(g => g.Key) // Order processors by first supported command
61-
.SelectMany(g => g);
57+
{
58+
var sortedProcessors = new SortedDictionary<int, IList<IImageWebProcessor>>();
59+
60+
foreach (IImageWebProcessor processor in processors)
61+
{
62+
// Get index of first supported command
63+
int index = commands.FindIndex(c => processor.Commands.Contains(c, StringComparer.OrdinalIgnoreCase));
64+
if (index != -1)
65+
{
66+
if (!sortedProcessors.TryGetValue(index, out IList<IImageWebProcessor> indexProcessors))
67+
{
68+
indexProcessors = new List<IImageWebProcessor>();
69+
sortedProcessors.Add(index, indexProcessors);
70+
}
71+
72+
indexProcessors.Add(processor);
73+
}
74+
}
75+
76+
// Return sorted processors
77+
foreach (IEnumerable<IImageWebProcessor> values in sortedProcessors.Values)
78+
{
79+
foreach (IImageWebProcessor value in values)
80+
{
81+
yield return value;
82+
}
83+
}
84+
}
6285
}
6386
}

0 commit comments

Comments
 (0)