Skip to content

Commit b7bf307

Browse files
Henr1k80nul800sebastiaan
authored andcommitted
Use GetIdsFromPathReversed to avoid allocating the string values of the integers parsed
1 parent 9e97f60 commit b7bf307

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

src/Umbraco.Core/Services/PublicAccessService.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System.Globalization;
2-
using System.Runtime.InteropServices;
31
using Microsoft.Extensions.DependencyInjection;
42
using Microsoft.Extensions.Logging;
53
using Umbraco.Cms.Core.DependencyInjection;
@@ -88,19 +86,14 @@ public IEnumerable<PublicAccessEntry> GetAll()
8886
{
8987
// Get all ids in the path for the content item and ensure they all
9088
// parse to ints that are not -1.
91-
var ids = contentPath.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries)
92-
.Select(x => int.TryParse(x, NumberStyles.Integer, CultureInfo.InvariantCulture, out var val) ? val : -1)
93-
.Where(x => x != -1)
94-
.ToList();
95-
96-
// start with the deepest id
97-
ids.Reverse();
89+
// Start with the deepest id.
90+
IEnumerable<int> ids = contentPath.GetIdsFromPathReversed().Where(x => x != -1);
9891

9992
using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
10093
{
10194
// This will retrieve from cache!
10295
var entries = _publicAccessRepository.GetMany().ToList();
103-
foreach (var id in CollectionsMarshal.AsSpan(ids))
96+
foreach (var id in ids)
10497
{
10598
PublicAccessEntry? found = entries.Find(x => x.ProtectedNodeId == id);
10699
if (found != null)

0 commit comments

Comments
 (0)