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:
parent
3a5cd6dd25
commit
a3c1b6d033
|
|
@ -12,6 +12,7 @@ namespace Microsoft.AspNetCore.Routing
|
||||||
{
|
{
|
||||||
public class RouteCollection : IRouteCollection
|
public class RouteCollection : IRouteCollection
|
||||||
{
|
{
|
||||||
|
private readonly static char[] UrlQueryDelimiters = new char[] { '?', '#' };
|
||||||
private readonly List<IRouter> _routes = new List<IRouter>();
|
private readonly List<IRouter> _routes = new List<IRouter>();
|
||||||
private readonly List<IRouter> _unnamedRoutes = new List<IRouter>();
|
private readonly List<IRouter> _unnamedRoutes = new List<IRouter>();
|
||||||
private readonly Dictionary<string, INamedRouter> _namedRoutes =
|
private readonly Dictionary<string, INamedRouter> _namedRoutes =
|
||||||
|
|
@ -140,7 +141,7 @@ namespace Microsoft.AspNetCore.Routing
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(url) && (_options.LowercaseUrls || _options.AppendTrailingSlash))
|
if (!string.IsNullOrEmpty(url) && (_options.LowercaseUrls || _options.AppendTrailingSlash))
|
||||||
{
|
{
|
||||||
var indexOfSeparator = url.IndexOfAny(new char[] { '?', '#' });
|
var indexOfSeparator = url.IndexOfAny(UrlQueryDelimiters);
|
||||||
var urlWithoutQueryString = url;
|
var urlWithoutQueryString = url;
|
||||||
var queryString = string.Empty;
|
var queryString = string.Empty;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue