Skip to content

Commit edff8f0

Browse files
committed
Replace allocating LINQ Reverse call with pre-sized reverse loop
1 parent 9b714fb commit edff8f0

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/JsonApiDotNetCore/Queries/Parsing/QueryExpressionParser.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,20 @@ protected virtual void Tokenize(string source)
5353
Source = source;
5454

5555
var tokenizer = new QueryTokenizer(source);
56-
TokenStack = new Stack<Token>(tokenizer.EnumerateTokens().Reverse());
56+
Token[] tokens = tokenizer.EnumerateTokens().ToArray();
57+
TokenStack = TokensToStack(tokens);
58+
}
59+
60+
private static Stack<Token> TokensToStack(Token[] tokens)
61+
{
62+
var stack = new Stack<Token>(tokens.Length);
63+
64+
for (int index = tokens.Length - 1; index >= 0; index--)
65+
{
66+
stack.Push(tokens[index]);
67+
}
68+
69+
return stack;
5770
}
5871

5972
/// <summary>

0 commit comments

Comments
 (0)