Perf: Use RouteValueDictionary in AnchorTagHelper rather than creating a new Dictionary (#4941)

* Perf: Use lighter, more optimized dictionaries for route sensitive TagHelpers

* Changing the project dependency to Routing.Abstractions
This commit is contained in:
mnltejaswini 2016-07-18 18:41:41 -07:00 committed by Ajay Bhargav Baaskaran
parent 52a7c112e8
commit 0240882031
2 changed files with 5 additions and 8 deletions

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers; using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.AspNetCore.Routing;
namespace Microsoft.AspNetCore.Mvc.TagHelpers namespace Microsoft.AspNetCore.Mvc.TagHelpers
{ {
@ -180,22 +181,17 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
} }
else else
{ {
IDictionary<string, object> routeValues = null; RouteValueDictionary routeValues = null;
if (_routeValues != null && _routeValues.Count > 0) if (_routeValues != null && _routeValues.Count > 0)
{ {
// Convert from Dictionary<string, string> to Dictionary<string, object>. routeValues = new RouteValueDictionary(_routeValues);
routeValues = new Dictionary<string, object>(_routeValues.Count, StringComparer.OrdinalIgnoreCase);
foreach (var routeValue in _routeValues)
{
routeValues.Add(routeValue.Key, routeValue.Value);
}
} }
if (Area != null) if (Area != null)
{ {
if (routeValues == null) if (routeValues == null)
{ {
routeValues = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase); routeValues = new RouteValueDictionary();
} }
// Unconditionally replace any value from asp-route-area. // Unconditionally replace any value from asp-route-area.

View File

@ -24,6 +24,7 @@
"dependencies": { "dependencies": {
"Microsoft.AspNetCore.Mvc.Razor": "1.1.0-*", "Microsoft.AspNetCore.Mvc.Razor": "1.1.0-*",
"Microsoft.Extensions.Caching.Memory": "1.1.0-*", "Microsoft.Extensions.Caching.Memory": "1.1.0-*",
"Microsoft.AspNetCore.Routing.Abstractions": "1.1.0-*",
"Microsoft.Extensions.FileSystemGlobbing": "1.1.0-*", "Microsoft.Extensions.FileSystemGlobbing": "1.1.0-*",
"Microsoft.Extensions.Logging.Abstractions": { "Microsoft.Extensions.Logging.Abstractions": {
"version": "1.1.0-*", "version": "1.1.0-*",