From a3c1b6d03335675927568c5289d94b345fa795a9 Mon Sep 17 00:00:00 2001 From: George Chakhidze <0xfeeddeadbeef@gmail.com> Date: Wed, 18 Oct 2017 00:19:29 +0400 Subject: [PATCH] Avoid allocation of a new char array on every request in RouteCollection class This is a very small micro-optimization: When LowercaseUrls and/or AppendTrailingSlash options are enabled, on every call to RouteCollection.NormalizeVirtualPath a new char[] { '?', '#' } is being allocated. --- src/Microsoft.AspNetCore.Routing/RouteCollection.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Routing/RouteCollection.cs b/src/Microsoft.AspNetCore.Routing/RouteCollection.cs index d0be724b5b..a2dae64291 100644 --- a/src/Microsoft.AspNetCore.Routing/RouteCollection.cs +++ b/src/Microsoft.AspNetCore.Routing/RouteCollection.cs @@ -12,6 +12,7 @@ namespace Microsoft.AspNetCore.Routing { public class RouteCollection : IRouteCollection { + private readonly static char[] UrlQueryDelimiters = new char[] { '?', '#' }; private readonly List _routes = new List(); private readonly List _unnamedRoutes = new List(); private readonly Dictionary _namedRoutes = @@ -140,7 +141,7 @@ namespace Microsoft.AspNetCore.Routing if (!string.IsNullOrEmpty(url) && (_options.LowercaseUrls || _options.AppendTrailingSlash)) { - var indexOfSeparator = url.IndexOfAny(new char[] { '?', '#' }); + var indexOfSeparator = url.IndexOfAny(UrlQueryDelimiters); var urlWithoutQueryString = url; var queryString = string.Empty; @@ -177,4 +178,4 @@ namespace Microsoft.AspNetCore.Routing } } } -} \ No newline at end of file +}