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.
This commit is contained in:
George Chakhidze 2017-10-18 00:19:29 +04:00 committed by Ryan Nowak
parent 3a5cd6dd25
commit a3c1b6d033
1 changed files with 3 additions and 2 deletions

View File

@ -12,6 +12,7 @@ namespace Microsoft.AspNetCore.Routing
{
public class RouteCollection : IRouteCollection
{
private readonly static char[] UrlQueryDelimiters = new char[] { '?', '#' };
private readonly List<IRouter> _routes = new List<IRouter>();
private readonly List<IRouter> _unnamedRoutes = new List<IRouter>();
private readonly Dictionary<string, INamedRouter> _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
}
}
}
}
}