Avoid allocating strings for parsing comma separated int values (#18199)
This commit is contained in:
@@ -5,6 +5,7 @@ using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -57,17 +58,24 @@ public static class StringExtensions
|
||||
/// <returns></returns>
|
||||
public static int[] GetIdsFromPathReversed(this string path)
|
||||
{
|
||||
string[] pathSegments = path.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries);
|
||||
List<int> nodeIds = new(pathSegments.Length);
|
||||
for (int i = pathSegments.Length - 1; i >= 0; i--)
|
||||
ReadOnlySpan<char> pathSpan = path.AsSpan();
|
||||
List<int> nodeIds = [];
|
||||
foreach (Range rangeOfPathSegment in pathSpan.Split(Constants.CharArrays.Comma))
|
||||
{
|
||||
if (int.TryParse(pathSegments[i], NumberStyles.Integer, CultureInfo.InvariantCulture, out int pathSegment))
|
||||
if (int.TryParse(pathSpan[rangeOfPathSegment], NumberStyles.Integer, CultureInfo.InvariantCulture, out int pathSegment))
|
||||
{
|
||||
nodeIds.Add(pathSegment);
|
||||
}
|
||||
}
|
||||
|
||||
return nodeIds.ToArray();
|
||||
var result = new int[nodeIds.Count];
|
||||
var resultIndex = 0;
|
||||
for (int i = nodeIds.Count - 1; i >= 0; i--)
|
||||
{
|
||||
result[resultIndex++] = nodeIds[i];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -14,7 +14,7 @@ using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Core.Services;
|
||||
|
||||
internal class PublicAccessService : RepositoryService, IPublicAccessService
|
||||
internal sealed class PublicAccessService : RepositoryService, IPublicAccessService
|
||||
{
|
||||
private readonly IPublicAccessRepository _publicAccessRepository;
|
||||
private readonly IEntityService _entityService;
|
||||
|
||||
@@ -2617,7 +2617,7 @@ internal partial class UserService : RepositoryService, IUserService
|
||||
{
|
||||
if (pathIds.Length == 0)
|
||||
{
|
||||
return new EntityPermissionCollection(Enumerable.Empty<EntityPermission>());
|
||||
return new EntityPermissionCollection([]);
|
||||
}
|
||||
|
||||
// get permissions for all nodes in the path by group
|
||||
|
||||
Reference in New Issue
Block a user