Skip to content

Commit 822c837

Browse files
Henr1k80nul800sebastiaan
authored andcommitted
Avoid allocating new empty arrays, reuse existing empty array
1 parent 4239f0f commit 822c837

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

src/Umbraco.Cms.Api.Delivery/Services/ApiMediaQueryService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private IPublishedMediaCache GetRequiredPublishedMediaCache()
185185
}
186186

187187

188-
private Attempt<PagedModel<Guid>, ApiMediaQueryOperationStatus> PagedResult(IEnumerable<IPublishedContent> children, int skip, int take)
188+
private static Attempt<PagedModel<Guid>, ApiMediaQueryOperationStatus> PagedResult(IEnumerable<IPublishedContent> children, int skip, int take)
189189
{
190190
IPublishedContent[] childrenAsArray = children as IPublishedContent[] ?? children.ToArray();
191191
var result = new PagedModel<Guid>

src/Umbraco.Core/Models/Membership/User.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public User(GlobalSettings globalSettings)
5353
_language = globalSettings.DefaultUILanguage;
5454
_isApproved = true;
5555
_isLockedOut = false;
56-
_startContentIds = new int[] { };
57-
_startMediaIds = new int[] { };
56+
_startContentIds = [];
57+
_startMediaIds = [];
5858

5959
// cannot be null
6060
_rawPasswordValue = string.Empty;
@@ -101,8 +101,8 @@ public User(GlobalSettings globalSettings, string? name, string email, string us
101101
_userGroups = new HashSet<IReadOnlyUserGroup>();
102102
_isApproved = true;
103103
_isLockedOut = false;
104-
_startContentIds = new int[] { };
105-
_startMediaIds = new int[] { };
104+
_startContentIds = [];
105+
_startMediaIds = [];
106106
}
107107

108108
/// <summary>

src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ public RelationRepository(IScopeAccessor scopeAccessor, ILogger<RelationReposito
3434
}
3535

3636
public IEnumerable<IUmbracoEntity> GetPagedParentEntitiesByChildId(int childId, long pageIndex, int pageSize, out long totalRecords, params Guid[] entityTypes)
37-
=> GetPagedParentEntitiesByChildId(childId, pageIndex, pageSize, out totalRecords, new int[0], entityTypes);
37+
=> GetPagedParentEntitiesByChildId(childId, pageIndex, pageSize, out totalRecords, [], entityTypes);
3838

3939
public IEnumerable<IUmbracoEntity> GetPagedChildEntitiesByParentId(int parentId, long pageIndex, int pageSize, out long totalRecords, params Guid[] entityTypes)
40-
=> GetPagedChildEntitiesByParentId(parentId, pageIndex, pageSize, out totalRecords, new int[0], entityTypes);
40+
=> GetPagedChildEntitiesByParentId(parentId, pageIndex, pageSize, out totalRecords, [], entityTypes);
4141

4242
public Task<PagedModel<IRelation>> GetPagedByChildKeyAsync(Guid childKey, int skip, int take, string? relationTypeAlias)
4343
{

src/Umbraco.Infrastructure/Persistence/Repositories/Implement/RelationTypeRepository.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement;
1717
/// <summary>
1818
/// Represents a repository for doing CRUD operations for <see cref="RelationType" />
1919
/// </summary>
20-
internal class RelationTypeRepository : EntityRepositoryBase<int, IRelationType>, IRelationTypeRepository
20+
internal sealed class RelationTypeRepository : EntityRepositoryBase<int, IRelationType>, IRelationTypeRepository
2121
{
2222
public RelationTypeRepository(IScopeAccessor scopeAccessor, AppCaches cache, ILogger<RelationTypeRepository> logger)
2323
: base(scopeAccessor, cache, logger)
@@ -27,7 +27,7 @@ public RelationTypeRepository(IScopeAccessor scopeAccessor, AppCaches cache, ILo
2727
protected override IRepositoryCachePolicy<IRelationType, int> CreateCachePolicy() =>
2828
new FullDataSetRepositoryCachePolicy<IRelationType, int>(GlobalIsolatedCache, ScopeAccessor, GetEntityId, /*expires:*/ true);
2929

30-
private void CheckNullObjectTypeValues(IRelationType entity)
30+
private static void CheckNullObjectTypeValues(IRelationType entity)
3131
{
3232
if (entity.ParentObjectType.HasValue && entity.ParentObjectType == Guid.Empty)
3333
{
@@ -66,12 +66,12 @@ protected override IEnumerable<IRelationType> PerformGetAll(params int[]? ids)
6666
public IEnumerable<IRelationType> GetMany(params Guid[]? ids)
6767
{
6868
// should not happen due to the cache policy
69-
if (ids?.Any() ?? false)
69+
if (ids is { Length: not 0 })
7070
{
7171
throw new NotImplementedException();
7272
}
7373

74-
return GetMany(new int[0]);
74+
return GetMany(Array.Empty<int>());
7575
}
7676

7777
protected override IEnumerable<IRelationType> PerformGetByQuery(IQuery<IRelationType> query)

src/Umbraco.Infrastructure/Security/BackOfficeIdentityUser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public int[] StartContentIds
6363
get => _startContentIds;
6464
set
6565
{
66-
value ??= new int[0];
66+
value ??= [];
6767

6868
BeingDirty.SetPropertyValueAndDetectChanges(value, ref _startContentIds!, nameof(StartContentIds), _startIdsComparer);
6969
}

src/Umbraco.Infrastructure/Security/BackOfficeUserStore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ public override Task<IdentityResult> CreateAsync(
138138
var userEntity = new User(_globalSettings, user.Name, user.Email, user.UserName, emptyPasswordValue)
139139
{
140140
Language = user.Culture ?? _globalSettings.DefaultUILanguage,
141-
StartContentIds = user.StartContentIds ?? new int[] { },
142-
StartMediaIds = user.StartMediaIds ?? new int[] { },
141+
StartContentIds = user.StartContentIds ?? [],
142+
StartMediaIds = user.StartMediaIds ?? [],
143143
IsLockedOut = user.IsLockedOut,
144144
Key = user.Key,
145145
Kind = user.Kind

0 commit comments

Comments
 (0)