Avoid allocating new empty arrays, reuse existing empty array

This commit is contained in:
Henrik Gedionsen
2025-03-31 14:12:54 +02:00
committed by Sebastiaan Janssen
parent 4239f0fc06
commit 822c8374ef
6 changed files with 14 additions and 14 deletions

View File

@@ -34,10 +34,10 @@ internal class RelationRepository : EntityRepositoryBase<int, IRelation>, IRelat
}
public IEnumerable<IUmbracoEntity> GetPagedParentEntitiesByChildId(int childId, long pageIndex, int pageSize, out long totalRecords, params Guid[] entityTypes)
=> GetPagedParentEntitiesByChildId(childId, pageIndex, pageSize, out totalRecords, new int[0], entityTypes);
=> GetPagedParentEntitiesByChildId(childId, pageIndex, pageSize, out totalRecords, [], entityTypes);
public IEnumerable<IUmbracoEntity> GetPagedChildEntitiesByParentId(int parentId, long pageIndex, int pageSize, out long totalRecords, params Guid[] entityTypes)
=> GetPagedChildEntitiesByParentId(parentId, pageIndex, pageSize, out totalRecords, new int[0], entityTypes);
=> GetPagedChildEntitiesByParentId(parentId, pageIndex, pageSize, out totalRecords, [], entityTypes);
public Task<PagedModel<IRelation>> GetPagedByChildKeyAsync(Guid childKey, int skip, int take, string? relationTypeAlias)
{

View File

@@ -17,7 +17,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement;
/// <summary>
/// Represents a repository for doing CRUD operations for <see cref="RelationType" />
/// </summary>
internal class RelationTypeRepository : EntityRepositoryBase<int, IRelationType>, IRelationTypeRepository
internal sealed class RelationTypeRepository : EntityRepositoryBase<int, IRelationType>, IRelationTypeRepository
{
public RelationTypeRepository(IScopeAccessor scopeAccessor, AppCaches cache, ILogger<RelationTypeRepository> logger)
: base(scopeAccessor, cache, logger)
@@ -27,7 +27,7 @@ internal class RelationTypeRepository : EntityRepositoryBase<int, IRelationType>
protected override IRepositoryCachePolicy<IRelationType, int> CreateCachePolicy() =>
new FullDataSetRepositoryCachePolicy<IRelationType, int>(GlobalIsolatedCache, ScopeAccessor, GetEntityId, /*expires:*/ true);
private void CheckNullObjectTypeValues(IRelationType entity)
private static void CheckNullObjectTypeValues(IRelationType entity)
{
if (entity.ParentObjectType.HasValue && entity.ParentObjectType == Guid.Empty)
{
@@ -66,12 +66,12 @@ internal class RelationTypeRepository : EntityRepositoryBase<int, IRelationType>
public IEnumerable<IRelationType> GetMany(params Guid[]? ids)
{
// should not happen due to the cache policy
if (ids?.Any() ?? false)
if (ids is { Length: not 0 })
{
throw new NotImplementedException();
}
return GetMany(new int[0]);
return GetMany(Array.Empty<int>());
}
protected override IEnumerable<IRelationType> PerformGetByQuery(IQuery<IRelationType> query)