Skip to content

Commit

Permalink
optimize preset request parser
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBobSquarePants committed Dec 5, 2023
1 parent d0dce52 commit 17aae94
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,13 @@ private static IDictionary<string, CommandCollection> ParsePresets(

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

Expand Down

0 comments on commit 17aae94

Please sign in to comment.