Skip to content

Commit d1b96c0

Browse files
Use ValueTuple to store processor index and remove LINQ usage
1 parent e2cf523 commit d1b96c0

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/ImageSharp.Web/Processors/WebProcessingExtensions.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Globalization;
7-
using System.Linq;
87
using Microsoft.Extensions.Logging;
98
using SixLabors.ImageSharp.Web.Commands;
109

@@ -55,31 +54,25 @@ public static FormattedImage Process(
5554
/// </returns>
5655
public static IEnumerable<IImageWebProcessor> GetBySupportedCommands(this IEnumerable<IImageWebProcessor> processors, List<string> commands)
5756
{
58-
var sortedProcessors = new SortedDictionary<int, IList<IImageWebProcessor>>();
57+
var indexedProcessors = new List<(int Index, IImageWebProcessor Processor)>();
5958

6059
foreach (IImageWebProcessor processor in processors)
6160
{
6261
// 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);
6464
if (index != -1)
6565
{
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));
7367
}
7468
}
7569

70+
indexedProcessors.Sort((x, y) => x.Index.CompareTo(y.Index));
71+
7672
// Return sorted processors
77-
foreach (IEnumerable<IImageWebProcessor> values in sortedProcessors.Values)
73+
foreach ((int _, IImageWebProcessor processor) in indexedProcessors)
7874
{
79-
foreach (IImageWebProcessor value in values)
80-
{
81-
yield return value;
82-
}
75+
yield return processor;
8376
}
8477
}
8578
}

0 commit comments

Comments
 (0)