Merge pull request #10861 from nzdev/v9/bugfix/trimstart-arrays
Reduce allocations by using existing CharArrays for TrimStart()
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
namespace Umbraco.Cms.Core
|
||||
namespace Umbraco.Cms.Core
|
||||
{
|
||||
public static partial class Constants
|
||||
{
|
||||
@@ -78,6 +78,12 @@
|
||||
/// </summary>
|
||||
public static readonly char[] TildeForwardSlash = new char[] { '~', '/' };
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Char array containing ~ / \
|
||||
/// </summary>
|
||||
public static readonly char[] TildeForwardSlashBackSlash = new char[] { '~', '/', '\\' };
|
||||
|
||||
/// <summary>
|
||||
/// Char array containing only ?
|
||||
/// </summary>
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace Umbraco.Cms.Core.Routing
|
||||
// and then the comparisons in IsMatch can be way faster - and allocate way less strings
|
||||
const string propertyAlias = Constants.Conventions.Content.UrlAlias;
|
||||
|
||||
var test1 = alias.TrimStart('/') + ",";
|
||||
var test1 = alias.TrimStart(Constants.CharArrays.ForwardSlash) + ",";
|
||||
var test2 = ",/" + test1; // test2 is ",/alias,"
|
||||
test1 = "," + test1; // test1 is ",alias,"
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Umbraco.Cms.Core.Routing
|
||||
public UmbracoRequestPaths(IOptions<GlobalSettings> globalSettings, IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
var applicationPath = hostingEnvironment.ApplicationVirtualPath;
|
||||
_appPath = applicationPath.TrimStart('/');
|
||||
_appPath = applicationPath.TrimStart(Constants.CharArrays.ForwardSlash);
|
||||
|
||||
_backOfficePath = globalSettings.Value.GetBackOfficePath(hostingEnvironment)
|
||||
.EnsureStartsWith('/').TrimStart(_appPath.EnsureStartsWith('/')).EnsureStartsWith('/');
|
||||
@@ -71,7 +71,7 @@ namespace Umbraco.Cms.Core.Routing
|
||||
/// </remarks>
|
||||
public bool IsBackOfficeRequest(string absPath)
|
||||
{
|
||||
var fullUrlPath = absPath.TrimStart('/');
|
||||
var fullUrlPath = absPath.TrimStart(Constants.CharArrays.ForwardSlash);
|
||||
var urlPath = fullUrlPath.TrimStart(_appPath).EnsureStartsWith('/');
|
||||
|
||||
// check if this is in the umbraco back office
|
||||
@@ -108,7 +108,7 @@ namespace Umbraco.Cms.Core.Routing
|
||||
// Umbraco/MYPLUGINAREA/MYCONTROLLERNAME/{action}/{id}
|
||||
// so if the path contains at a minimum 3 parts: Umbraco + MYPLUGINAREA + MYCONTROLLERNAME then we will have to assume it is a
|
||||
// plugin controller for the front-end.
|
||||
if (urlPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Length >= 3)
|
||||
if (urlPath.Split(Constants.CharArrays.ForwardSlash, StringSplitOptions.RemoveEmptyEntries).Length >= 3)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace Umbraco.Cms.Web.Common.AspNetCore
|
||||
throw new ArgumentException("The path appears to already be fully qualified. Please remove the call to MapPath");
|
||||
}
|
||||
|
||||
return Path.Combine(root, newPath.TrimStart('~', '/', '\\'));
|
||||
return Path.Combine(root, newPath.TrimStart(Core.Constants.CharArrays.TildeForwardSlashBackSlash));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
Reference in New Issue
Block a user