[Perf] Avoid Linq method and save its related allocations in TreeRouter

This commit is contained in:
mnltejaswini 2016-02-26 11:19:57 -08:00
parent 1c9a54aeb8
commit 41e3acf0fa
2 changed files with 20 additions and 2 deletions

View File

@ -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;
}
}
}

View File

@ -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)
{