From 60fe77c089217211f3632e3a0528df75132d6bac Mon Sep 17 00:00:00 2001 From: Dmitry Lyzo <56478732+dmitrylyzo@users.noreply.github.com> Date: Sun, 16 Jan 2022 13:34:52 +0300 Subject: [PATCH] Remove unnecessary array allocation Co-authored-by: Claus Vium --- Jellyfin.Api/Controllers/UserLibraryController.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Jellyfin.Api/Controllers/UserLibraryController.cs b/Jellyfin.Api/Controllers/UserLibraryController.cs index fa07d8085..90cb4a74a 100644 --- a/Jellyfin.Api/Controllers/UserLibraryController.cs +++ b/Jellyfin.Api/Controllers/UserLibraryController.cs @@ -210,15 +210,12 @@ namespace Jellyfin.Api.Controllers if (item is IHasTrailers hasTrailers) { var trailers = hasTrailers.LocalTrailers; - var dtosTrailers = _dtoService.GetBaseItemDtos(trailers, dtoOptions, user, item); - var allTrailers = new BaseItemDto[dtosTrailers.Count]; - dtosTrailers.CopyTo(allTrailers, 0); - return allTrailers; + return Ok(_dtoService.GetBaseItemDtos(trailers, dtoOptions, user, item)); } - return item.GetExtras(new[] { ExtraType.Trailer }) - .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item)) - .ToArray(); + return Ok(item.GetExtras() + .Where(e => e.ExtraType == ExtraType.Trailer) + .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item))); } ///