|
4 | 4 | using System; |
5 | 5 | using System.Collections.Generic; |
6 | 6 | using System.Globalization; |
7 | | -using System.Linq; |
8 | 7 | using Microsoft.Extensions.Logging; |
9 | 8 | using SixLabors.ImageSharp.Web.Commands; |
10 | 9 |
|
@@ -55,31 +54,25 @@ public static FormattedImage Process( |
55 | 54 | /// </returns> |
56 | 55 | public static IEnumerable<IImageWebProcessor> GetBySupportedCommands(this IEnumerable<IImageWebProcessor> processors, List<string> commands) |
57 | 56 | { |
58 | | - var sortedProcessors = new SortedDictionary<int, IList<IImageWebProcessor>>(); |
| 57 | + var indexedProcessors = new List<(int Index, IImageWebProcessor Processor)>(); |
59 | 58 |
|
60 | 59 | foreach (IImageWebProcessor processor in processors) |
61 | 60 | { |
62 | 61 | // Get index of first supported command |
63 | | - int index = commands.FindIndex(c => processor.Commands.Contains(c, StringComparer.OrdinalIgnoreCase)); |
| 62 | + var processorCommands = new List<string>(processor.Commands); |
| 63 | + int index = commands.FindIndex(c => processorCommands.FindIndex(pc => pc.Equals(c, StringComparison.OrdinalIgnoreCase)) != -1); |
64 | 64 | if (index != -1) |
65 | 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); |
| 66 | + indexedProcessors.Add((index, processor)); |
73 | 67 | } |
74 | 68 | } |
75 | 69 |
|
| 70 | + indexedProcessors.Sort((x, y) => x.Index.CompareTo(y.Index)); |
| 71 | + |
76 | 72 | // Return sorted processors |
77 | | - foreach (IEnumerable<IImageWebProcessor> values in sortedProcessors.Values) |
| 73 | + foreach ((int _, IImageWebProcessor processor) in indexedProcessors) |
78 | 74 | { |
79 | | - foreach (IImageWebProcessor value in values) |
80 | | - { |
81 | | - yield return value; |
82 | | - } |
| 75 | + yield return processor; |
83 | 76 | } |
84 | 77 | } |
85 | 78 | } |
|
0 commit comments