From 7f38af3701aa06e2281799ffeac59e875eaec5db Mon Sep 17 00:00:00 2001 From: Vasily Date: Fri, 28 Feb 2020 17:27:16 +0300 Subject: [PATCH] Remove custom queue class as it is not needed --- MediaBrowser.Controller/Entities/Folder.cs | 45 +++++----------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index b134dfde2..cda4c31ad 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -807,52 +807,27 @@ namespace MediaBrowser.Controller.Entities return false; } - private class OneTimeQueue - { - private List items; - private int start; - public OneTimeQueue(int capacity) - { - items = new List(capacity); - start = 0; - } - public OneTimeQueue(int capacity, T first) - { - items = new List(capacity); - items.Add(first); - start = 0; - } - public void Enqueue(T item) - { - items.Add(item); - } - public T Dequeue() - { - start++; - return items[start - 1]; - } - } - private IReadOnlyList SortItemsByRequest(InternalItemsQuery query, IReadOnlyList items) { var ids = query.ItemIds; - var positions = new Dictionary>(ids.Length); + int size = items.Count; + + // ids can potentially contain non-unique guids, but query result cannot, + // so we include only first occurrence of each guid + var positions = new Dictionary(size); + int index = 0; for (int i = 0; i < ids.Length; i++) { - if (positions.TryGetValue(ids[i], out var q)) + if (positions.TryAdd(ids[i], index)) { - q.Enqueue(i); - } - else - { - positions.Add(ids[i], new OneTimeQueue(4 /* wild guess */, i)); + index++; } } - var newItems = new BaseItem[ids.Count]; + var newItems = new BaseItem[size]; foreach(var item in items) { - newItems[positions[item.Id].Dequeue()] = item; + newItems[positions[item.Id]] = item; } return newItems; }