From 02408820313d6185a81253a0c82c9be06221131c Mon Sep 17 00:00:00 2001 From: mnltejaswini Date: Mon, 18 Jul 2016 18:41:41 -0700 Subject: [PATCH] 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 --- .../AnchorTagHelper.cs | 12 ++++-------- src/Microsoft.AspNetCore.Mvc.TagHelpers/project.json | 1 + 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/AnchorTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/AnchorTagHelper.cs index 1dd7a2583d..d4d7787952 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/AnchorTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/AnchorTagHelper.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Razor.TagHelpers; +using Microsoft.AspNetCore.Routing; namespace Microsoft.AspNetCore.Mvc.TagHelpers { @@ -180,22 +181,17 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers } else { - IDictionary routeValues = null; + RouteValueDictionary routeValues = null; if (_routeValues != null && _routeValues.Count > 0) { - // Convert from Dictionary to Dictionary. - routeValues = new Dictionary(_routeValues.Count, StringComparer.OrdinalIgnoreCase); - foreach (var routeValue in _routeValues) - { - routeValues.Add(routeValue.Key, routeValue.Value); - } + routeValues = new RouteValueDictionary(_routeValues); } if (Area != null) { if (routeValues == null) { - routeValues = new Dictionary(StringComparer.OrdinalIgnoreCase); + routeValues = new RouteValueDictionary(); } // Unconditionally replace any value from asp-route-area. diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/project.json b/src/Microsoft.AspNetCore.Mvc.TagHelpers/project.json index b51378757d..87d4181402 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/project.json +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/project.json @@ -24,6 +24,7 @@ "dependencies": { "Microsoft.AspNetCore.Mvc.Razor": "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.Logging.Abstractions": { "version": "1.1.0-*",