[Perf] Avoid Linq method and save its related allocations in TreeRouter
This commit is contained in:
parent
1c9a54aeb8
commit
41e3acf0fa
|
|
@ -59,5 +59,24 @@ namespace Microsoft.AspNetCore.Routing.Template
|
|||
{
|
||||
return string.Join(SeparatorString, Segments.Select(s => s.DebuggerToString()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the parameter matching the given name.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the parameter to match.</param>
|
||||
/// <returns>The matching parameter or <c>null</c> if no parameter matches the given name.</returns>
|
||||
public TemplatePart GetParameter(string name)
|
||||
{
|
||||
for (var i = 0; i < Parameters.Count; i++)
|
||||
{
|
||||
var parameter = Parameters[i];
|
||||
if (string.Equals(parameter.Name, name, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return parameter;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -386,8 +386,7 @@ namespace Microsoft.AspNetCore.Routing.Tree
|
|||
{
|
||||
if (entry.RequiredLinkValues.ContainsKey(kvp.Key))
|
||||
{
|
||||
var parameter = entry.Template.Parameters
|
||||
.FirstOrDefault(p => string.Equals(p.Name, kvp.Key, StringComparison.OrdinalIgnoreCase));
|
||||
var parameter = entry.Template.GetParameter(kvp.Key);
|
||||
|
||||
if (parameter == null)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue