From b7bf30744ae5c9c073b30aaef5c2d7fc18b4312a Mon Sep 17 00:00:00 2001 From: Henrik Gedionsen Date: Tue, 8 Apr 2025 15:08:43 +0200 Subject: [PATCH] Use GetIdsFromPathReversed to avoid allocating the string values of the integers parsed --- src/Umbraco.Core/Services/PublicAccessService.cs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/Umbraco.Core/Services/PublicAccessService.cs b/src/Umbraco.Core/Services/PublicAccessService.cs index 6919ab8d3f..2c083ea0fa 100644 --- a/src/Umbraco.Core/Services/PublicAccessService.cs +++ b/src/Umbraco.Core/Services/PublicAccessService.cs @@ -1,5 +1,3 @@ -using System.Globalization; -using System.Runtime.InteropServices; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Umbraco.Cms.Core.DependencyInjection; @@ -88,19 +86,14 @@ internal sealed class PublicAccessService : RepositoryService, IPublicAccessServ { // Get all ids in the path for the content item and ensure they all // parse to ints that are not -1. - var ids = contentPath.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries) - .Select(x => int.TryParse(x, NumberStyles.Integer, CultureInfo.InvariantCulture, out var val) ? val : -1) - .Where(x => x != -1) - .ToList(); - - // start with the deepest id - ids.Reverse(); + // Start with the deepest id. + IEnumerable ids = contentPath.GetIdsFromPathReversed().Where(x => x != -1); using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true)) { // This will retrieve from cache! var entries = _publicAccessRepository.GetMany().ToList(); - foreach (var id in CollectionsMarshal.AsSpan(ids)) + foreach (var id in ids) { PublicAccessEntry? found = entries.Find(x => x.ProtectedNodeId == id); if (found != null)