mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-18 00:06:27 +01:00
More efficient array creation (#11468)
This commit is contained in:
@@ -127,15 +127,11 @@ namespace Emby.Server.Implementations.AppBase
|
||||
|
||||
if (_configurationFactories is null)
|
||||
{
|
||||
_configurationFactories = new[] { factory };
|
||||
_configurationFactories = [factory];
|
||||
}
|
||||
else
|
||||
{
|
||||
var oldLen = _configurationFactories.Length;
|
||||
var arr = new IConfigurationFactory[oldLen + 1];
|
||||
_configurationFactories.CopyTo(arr, 0);
|
||||
arr[oldLen] = factory;
|
||||
_configurationFactories = arr;
|
||||
_configurationFactories = [.._configurationFactories, factory];
|
||||
}
|
||||
|
||||
_configurationStores = _configurationFactories
|
||||
|
||||
@@ -2323,14 +2323,7 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
columns.Add(builder.ToString());
|
||||
|
||||
var oldLen = query.ExcludeItemIds.Length;
|
||||
var newLen = oldLen + item.ExtraIds.Length + 1;
|
||||
var excludeIds = new Guid[newLen];
|
||||
query.ExcludeItemIds.CopyTo(excludeIds, 0);
|
||||
excludeIds[oldLen] = item.Id;
|
||||
item.ExtraIds.CopyTo(excludeIds, oldLen + 1);
|
||||
|
||||
query.ExcludeItemIds = excludeIds;
|
||||
query.ExcludeItemIds = [..query.ExcludeItemIds, item.Id, ..item.ExtraIds];
|
||||
query.ExcludeProviderIds = item.ProviderIds;
|
||||
}
|
||||
|
||||
@@ -2838,10 +2831,7 @@ namespace Emby.Server.Implementations.Data
|
||||
prepend.Add((ItemSortBy.Random, SortOrder.Ascending));
|
||||
}
|
||||
|
||||
var arr = new (ItemSortBy, SortOrder)[prepend.Count + orderBy.Count];
|
||||
prepend.CopyTo(arr, 0);
|
||||
orderBy.CopyTo(arr, prepend.Count);
|
||||
orderBy = query.OrderBy = arr;
|
||||
orderBy = query.OrderBy = [..prepend, ..orderBy];
|
||||
}
|
||||
else if (orderBy.Count == 0)
|
||||
{
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace Emby.Server.Implementations.Library
|
||||
}
|
||||
};
|
||||
|
||||
private static readonly Glob[] _globs = _patterns.Select(p => Glob.Parse(p, _globOptions)).ToArray();
|
||||
private static readonly Glob[] _globs = Array.ConvertAll(_patterns, p => Glob.Parse(p, _globOptions));
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the supplied path should be ignored.
|
||||
|
||||
@@ -3038,9 +3038,7 @@ namespace Emby.Server.Implementations.Library
|
||||
{
|
||||
var libraryOptions = CollectionFolder.GetLibraryOptions(virtualFolderPath);
|
||||
|
||||
var list = libraryOptions.PathInfos.ToList();
|
||||
list.Add(pathInfo);
|
||||
libraryOptions.PathInfos = list.ToArray();
|
||||
libraryOptions.PathInfos = [..libraryOptions.PathInfos, pathInfo];
|
||||
|
||||
SyncLibraryOptionsToLocations(virtualFolderPath, libraryOptions);
|
||||
|
||||
@@ -3059,8 +3057,7 @@ namespace Emby.Server.Implementations.Library
|
||||
|
||||
SyncLibraryOptionsToLocations(virtualFolderPath, libraryOptions);
|
||||
|
||||
var list = libraryOptions.PathInfos.ToList();
|
||||
foreach (var originalPathInfo in list)
|
||||
foreach (var originalPathInfo in libraryOptions.PathInfos)
|
||||
{
|
||||
if (string.Equals(mediaPath.Path, originalPathInfo.Path, StringComparison.Ordinal))
|
||||
{
|
||||
@@ -3069,8 +3066,6 @@ namespace Emby.Server.Implementations.Library
|
||||
}
|
||||
}
|
||||
|
||||
libraryOptions.PathInfos = list.ToArray();
|
||||
|
||||
CollectionFolder.SaveLibraryOptions(virtualFolderPath, libraryOptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -303,8 +303,8 @@ namespace Emby.Server.Implementations.Library
|
||||
{
|
||||
// Handle situations with the grouping setting, e.g. movies showing up in tv, etc.
|
||||
// Thanks to mixed content libraries included in the UserView
|
||||
var hasCollectionType = parents.OfType<UserView>().ToArray();
|
||||
if (hasCollectionType.Length > 0)
|
||||
var hasCollectionType = parents.OfType<UserView>().ToList();
|
||||
if (hasCollectionType.Count > 0)
|
||||
{
|
||||
if (hasCollectionType.All(i => i.CollectionType == CollectionType.movies))
|
||||
{
|
||||
|
||||
@@ -226,13 +226,8 @@ namespace Emby.Server.Implementations.Playlists
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a new array with the updated playlist items
|
||||
var newLinkedChildren = new LinkedChild[playlist.LinkedChildren.Length + childrenToAdd.Count];
|
||||
playlist.LinkedChildren.CopyTo(newLinkedChildren, 0);
|
||||
childrenToAdd.CopyTo(newLinkedChildren, playlist.LinkedChildren.Length);
|
||||
|
||||
// Update the playlist in the repository
|
||||
playlist.LinkedChildren = newLinkedChildren;
|
||||
playlist.LinkedChildren = [..playlist.LinkedChildren, ..childrenToAdd];
|
||||
|
||||
await UpdatePlaylistInternal(playlist).ConfigureAwait(false);
|
||||
|
||||
@@ -526,8 +521,8 @@ namespace Emby.Server.Implementations.Playlists
|
||||
foreach (var playlist in playlists)
|
||||
{
|
||||
// Update owner if shared
|
||||
var rankedShares = playlist.Shares.OrderByDescending(x => x.CanEdit).ToArray();
|
||||
if (rankedShares.Length > 0)
|
||||
var rankedShares = playlist.Shares.OrderByDescending(x => x.CanEdit).ToList();
|
||||
if (rankedShares.Count > 0)
|
||||
{
|
||||
playlist.OwnerUserId = rankedShares[0].UserId;
|
||||
playlist.Shares = rankedShares.Skip(1).ToArray();
|
||||
|
||||
@@ -256,8 +256,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
||||
{
|
||||
get
|
||||
{
|
||||
var triggers = InternalTriggers;
|
||||
return triggers.Select(i => i.Item1).ToArray();
|
||||
return Array.ConvertAll(InternalTriggers, i => i.Item1);
|
||||
}
|
||||
|
||||
set
|
||||
@@ -269,7 +268,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
||||
|
||||
SaveTriggers(triggerList);
|
||||
|
||||
InternalTriggers = triggerList.Select(i => new Tuple<TaskTriggerInfo, ITaskTrigger>(i, GetTrigger(i))).ToArray();
|
||||
InternalTriggers = Array.ConvertAll(triggerList, i => new Tuple<TaskTriggerInfo, ITaskTrigger>(i, GetTrigger(i)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -503,7 +502,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
||||
private Tuple<TaskTriggerInfo, ITaskTrigger>[] LoadTriggers()
|
||||
{
|
||||
// This null check is not great, but is needed to handle bad user input, or user mucking with the config file incorrectly
|
||||
var settings = LoadTriggerSettings().Where(i => i is not null).ToArray();
|
||||
var settings = LoadTriggerSettings().Where(i => i is not null);
|
||||
|
||||
return settings.Select(i => new Tuple<TaskTriggerInfo, ITaskTrigger>(i, GetTrigger(i))).ToArray();
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ namespace Emby.Server.Implementations.Session
|
||||
{
|
||||
session.NowPlayingQueue = nowPlayingQueue;
|
||||
|
||||
var itemIds = nowPlayingQueue.Select(queue => queue.Id).ToArray();
|
||||
var itemIds = Array.ConvertAll(nowPlayingQueue, queue => queue.Id);
|
||||
session.NowPlayingQueueFullItems = _dtoService.GetBaseItemDtos(
|
||||
_libraryManager.GetItemList(new InternalItemsQuery { ItemIds = itemIds }),
|
||||
new DtoOptions(true));
|
||||
@@ -1386,16 +1386,13 @@ namespace Emby.Server.Implementations.Session
|
||||
if (session.AdditionalUsers.All(i => !i.UserId.Equals(userId)))
|
||||
{
|
||||
var user = _userManager.GetUserById(userId);
|
||||
|
||||
var list = session.AdditionalUsers.ToList();
|
||||
|
||||
list.Add(new SessionUserInfo
|
||||
var newUser = new SessionUserInfo
|
||||
{
|
||||
UserId = userId,
|
||||
UserName = user.Username
|
||||
});
|
||||
};
|
||||
|
||||
session.AdditionalUsers = list.ToArray();
|
||||
session.AdditionalUsers = [..session.AdditionalUsers, newUser];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user