From 3eb4fa9e92b0061df39b20e62616c5bff1fa7240 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Tue, 6 Feb 2018 16:59:14 -0500 Subject: [PATCH] Potential optimization in ScrollQueue --- ICD.Common.Utils/Collections/ScrollQueue.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ICD.Common.Utils/Collections/ScrollQueue.cs b/ICD.Common.Utils/Collections/ScrollQueue.cs index 36729d6..e580c71 100644 --- a/ICD.Common.Utils/Collections/ScrollQueue.cs +++ b/ICD.Common.Utils/Collections/ScrollQueue.cs @@ -1,8 +1,8 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Linq; using ICD.Common.Properties; +using ICD.Common.Utils.Extensions; namespace ICD.Common.Utils.Collections { @@ -86,8 +86,17 @@ namespace ICD.Common.Utils.Collections [PublicAPI] public void Enqueue(TContents item) { - m_CollectionLock.Execute(() => m_Collection.AddLast(item)); - Trim(); + m_CollectionLock.Enter(); + + try + { + m_Collection.AddLast(item); + Trim(); + } + finally + { + m_CollectionLock.Leave(); + } } /// @@ -132,7 +141,7 @@ namespace ICD.Common.Utils.Collections public IEnumerator GetEnumerator() { - return m_CollectionLock.Execute(() => m_Collection.ToList().GetEnumerator()); + return m_CollectionLock.Execute(() => m_Collection.ToList(Count).GetEnumerator()); } void ICollection.CopyTo(Array myArr, int index)