Avoid allocating new empty arrays, reuse existing empty array
This commit is contained in:
committed by
Sebastiaan Janssen
parent
4239f0fc06
commit
822c8374ef
@@ -185,7 +185,7 @@ internal sealed class ApiMediaQueryService : IApiMediaQueryService
|
||||
}
|
||||
|
||||
|
||||
private Attempt<PagedModel<Guid>, ApiMediaQueryOperationStatus> PagedResult(IEnumerable<IPublishedContent> children, int skip, int take)
|
||||
private static Attempt<PagedModel<Guid>, ApiMediaQueryOperationStatus> PagedResult(IEnumerable<IPublishedContent> children, int skip, int take)
|
||||
{
|
||||
IPublishedContent[] childrenAsArray = children as IPublishedContent[] ?? children.ToArray();
|
||||
var result = new PagedModel<Guid>
|
||||
|
||||
@@ -53,8 +53,8 @@ public class User : EntityBase, IUser, IProfile
|
||||
_language = globalSettings.DefaultUILanguage;
|
||||
_isApproved = true;
|
||||
_isLockedOut = false;
|
||||
_startContentIds = new int[] { };
|
||||
_startMediaIds = new int[] { };
|
||||
_startContentIds = [];
|
||||
_startMediaIds = [];
|
||||
|
||||
// cannot be null
|
||||
_rawPasswordValue = string.Empty;
|
||||
@@ -101,8 +101,8 @@ public class User : EntityBase, IUser, IProfile
|
||||
_userGroups = new HashSet<IReadOnlyUserGroup>();
|
||||
_isApproved = true;
|
||||
_isLockedOut = false;
|
||||
_startContentIds = new int[] { };
|
||||
_startMediaIds = new int[] { };
|
||||
_startContentIds = [];
|
||||
_startMediaIds = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -63,7 +63,7 @@ public class BackOfficeIdentityUser : UmbracoIdentityUser
|
||||
get => _startContentIds;
|
||||
set
|
||||
{
|
||||
value ??= new int[0];
|
||||
value ??= [];
|
||||
|
||||
BeingDirty.SetPropertyValueAndDetectChanges(value, ref _startContentIds!, nameof(StartContentIds), _startIdsComparer);
|
||||
}
|
||||
|
||||
@@ -138,8 +138,8 @@ public class BackOfficeUserStore :
|
||||
var userEntity = new User(_globalSettings, user.Name, user.Email, user.UserName, emptyPasswordValue)
|
||||
{
|
||||
Language = user.Culture ?? _globalSettings.DefaultUILanguage,
|
||||
StartContentIds = user.StartContentIds ?? new int[] { },
|
||||
StartMediaIds = user.StartMediaIds ?? new int[] { },
|
||||
StartContentIds = user.StartContentIds ?? [],
|
||||
StartMediaIds = user.StartMediaIds ?? [],
|
||||
IsLockedOut = user.IsLockedOut,
|
||||
Key = user.Key,
|
||||
Kind = user.Kind
|
||||
|
||||
Reference in New Issue
Block a user