Skip to content

Commit 17aae94

Browse files
optimize preset request parser
1 parent d0dce52 commit 17aae94

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/ImageSharp.Web/Commands/PresetOnlyQueryCollectionRequestParser.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,13 @@ private static IDictionary<string, CommandCollection> ParsePresets(
5858

5959
private static CommandCollection ParsePreset(string unparsedPresetValue)
6060
{
61-
// TODO: Investigate skipping the double allocation here.
62-
// In .NET 6 we can directly use the QueryStringEnumerable type and enumerate stright to our command collection
63-
Dictionary<string, StringValues> parsed = QueryHelpers.ParseQuery(unparsedPresetValue);
6461
CommandCollection transformed = new();
65-
foreach (KeyValuePair<string, StringValues> pair in parsed)
62+
foreach (QueryStringEnumerable.EncodedNameValuePair pair in new QueryStringEnumerable(unparsedPresetValue))
6663
{
67-
// Use the indexer for both set and query. This replaces any previously parsed values.
68-
string? value = pair.Value[^1];
69-
if (value is not null)
64+
// Last value wins.
65+
if (pair.DecodeValue().Length > 0)
7066
{
71-
transformed[pair.Key] = value;
67+
transformed[pair.DecodeName().ToString()] = pair.DecodeValue().ToString();
7268
}
7369
}
7470

0 commit comments

Comments
 (0)