mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-02 13:58:29 +01:00
More efficient array creation (#11468)
This commit is contained in:
@@ -1779,14 +1779,11 @@ namespace MediaBrowser.Controller.Entities
|
||||
int curLen = current.Length;
|
||||
if (curLen == 0)
|
||||
{
|
||||
Studios = new[] { name };
|
||||
Studios = [name];
|
||||
}
|
||||
else
|
||||
{
|
||||
var newArr = new string[curLen + 1];
|
||||
current.CopyTo(newArr, 0);
|
||||
newArr[curLen] = name;
|
||||
Studios = newArr;
|
||||
Studios = [..current, name];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1808,9 +1805,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
var genres = Genres;
|
||||
if (!genres.Contains(name, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var list = genres.ToList();
|
||||
list.Add(name);
|
||||
Genres = list.ToArray();
|
||||
Genres = [..genres, name];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1980,12 +1975,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
public void AddImage(ItemImageInfo image)
|
||||
{
|
||||
var current = ImageInfos;
|
||||
var currentCount = current.Length;
|
||||
var newArr = new ItemImageInfo[currentCount + 1];
|
||||
current.CopyTo(newArr, 0);
|
||||
newArr[currentCount] = image;
|
||||
ImageInfos = newArr;
|
||||
ImageInfos = [..ImageInfos, image];
|
||||
}
|
||||
|
||||
public virtual Task UpdateToRepositoryAsync(ItemUpdateType updateReason, CancellationToken cancellationToken)
|
||||
|
||||
@@ -30,15 +30,11 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
if (item.RemoteTrailers.Count == 0)
|
||||
{
|
||||
item.RemoteTrailers = new[] { mediaUrl };
|
||||
item.RemoteTrailers = [mediaUrl];
|
||||
}
|
||||
else
|
||||
{
|
||||
var oldIds = item.RemoteTrailers;
|
||||
var newIds = new MediaUrl[oldIds.Count + 1];
|
||||
oldIds.CopyTo(newIds);
|
||||
newIds[oldIds.Count] = mediaUrl;
|
||||
item.RemoteTrailers = newIds;
|
||||
item.RemoteTrailers = [..item.RemoteTrailers, mediaUrl];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,11 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
if (current.Length == 0)
|
||||
{
|
||||
item.Tags = new[] { name };
|
||||
item.Tags = [name];
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Tags = current.Concat(new[] { name }).ToArray();
|
||||
item.Tags = [..current, name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,8 +116,8 @@ namespace MediaBrowser.Controller.Library
|
||||
{
|
||||
get
|
||||
{
|
||||
var paths = string.IsNullOrEmpty(Path) ? Array.Empty<string>() : new[] { Path };
|
||||
return AdditionalLocations is null ? paths : paths.Concat(AdditionalLocations).ToArray();
|
||||
var paths = string.IsNullOrEmpty(Path) ? Array.Empty<string>() : [Path];
|
||||
return AdditionalLocations is null ? paths : [..paths, ..AdditionalLocations];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -288,7 +288,7 @@ namespace MediaBrowser.Controller.Net
|
||||
|
||||
lock (_activeConnectionsLock)
|
||||
{
|
||||
foreach (var connection in _activeConnections.ToArray())
|
||||
foreach (var connection in _activeConnections.ToList())
|
||||
{
|
||||
DisposeConnection(connection);
|
||||
}
|
||||
|
||||
@@ -270,9 +270,7 @@ namespace MediaBrowser.Controller.Session
|
||||
|
||||
public void AddController(ISessionController controller)
|
||||
{
|
||||
var controllers = SessionControllers.ToList();
|
||||
controllers.Add(controller);
|
||||
SessionControllers = controllers.ToArray();
|
||||
SessionControllers = [..SessionControllers, controller];
|
||||
}
|
||||
|
||||
public bool ContainsUser(Guid userId)
|
||||
|
||||
Reference in New Issue
Block a user