mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 13:15:07 +00:00
perf: Removing redundant code, logging micro-optimization
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using ICD.Common.Properties;
|
using ICD.Common.Properties;
|
||||||
using ICD.Common.Utils.Extensions;
|
|
||||||
|
|
||||||
namespace ICD.Common.Utils.Collections
|
namespace ICD.Common.Utils.Collections
|
||||||
{
|
{
|
||||||
@@ -16,8 +15,6 @@ namespace ICD.Common.Utils.Collections
|
|||||||
private readonly LinkedList<TContents> m_Collection;
|
private readonly LinkedList<TContents> m_Collection;
|
||||||
private int m_MaxSize;
|
private int m_MaxSize;
|
||||||
|
|
||||||
private readonly SafeCriticalSection m_CollectionLock;
|
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -41,13 +38,13 @@ namespace ICD.Common.Utils.Collections
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the number of items in the collection.
|
/// Gets the number of items in the collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Count { get { return m_CollectionLock.Execute(() => m_Collection.Count); } }
|
public int Count { get { return m_Collection.Count; } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The IsSynchronized Boolean property returns True if the
|
/// The IsSynchronized Boolean property returns True if the
|
||||||
/// collection is designed to be thread safe; otherwise, it returns False.
|
/// collection is designed to be thread safe; otherwise, it returns False.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsSynchronized { get { return true; } }
|
public bool IsSynchronized { get { return false; } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The SyncRoot property returns an object, which is used for synchronizing
|
/// The SyncRoot property returns an object, which is used for synchronizing
|
||||||
@@ -64,7 +61,6 @@ namespace ICD.Common.Utils.Collections
|
|||||||
/// <param name="maxSize"></param>
|
/// <param name="maxSize"></param>
|
||||||
public ScrollQueue(int maxSize)
|
public ScrollQueue(int maxSize)
|
||||||
{
|
{
|
||||||
m_CollectionLock = new SafeCriticalSection();
|
|
||||||
m_Collection = new LinkedList<TContents>();
|
m_Collection = new LinkedList<TContents>();
|
||||||
MaxSize = maxSize;
|
MaxSize = maxSize;
|
||||||
}
|
}
|
||||||
@@ -76,7 +72,7 @@ namespace ICD.Common.Utils.Collections
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
m_CollectionLock.Execute(() => m_Collection.Clear());
|
m_Collection.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -85,19 +81,10 @@ namespace ICD.Common.Utils.Collections
|
|||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public void Enqueue(TContents item)
|
public void Enqueue(TContents item)
|
||||||
{
|
|
||||||
m_CollectionLock.Enter();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
m_Collection.AddLast(item);
|
m_Collection.AddLast(item);
|
||||||
Trim();
|
Trim();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
m_CollectionLock.Leave();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes the oldest item from the queue.
|
/// Removes the oldest item from the queue.
|
||||||
@@ -106,19 +93,10 @@ namespace ICD.Common.Utils.Collections
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public TContents Dequeue()
|
public TContents Dequeue()
|
||||||
{
|
{
|
||||||
m_CollectionLock.Enter();
|
TContents output = Peek();
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TContents output = m_Collection.First.Value;
|
|
||||||
m_Collection.RemoveFirst();
|
m_Collection.RemoveFirst();
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
m_CollectionLock.Leave();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the oldest item in the queue.
|
/// Returns the oldest item in the queue.
|
||||||
@@ -127,7 +105,7 @@ namespace ICD.Common.Utils.Collections
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public TContents Peek()
|
public TContents Peek()
|
||||||
{
|
{
|
||||||
return m_CollectionLock.Execute(() => m_Collection.First.Value);
|
return m_Collection.First.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -141,14 +119,10 @@ namespace ICD.Common.Utils.Collections
|
|||||||
|
|
||||||
public IEnumerator<TContents> GetEnumerator()
|
public IEnumerator<TContents> GetEnumerator()
|
||||||
{
|
{
|
||||||
return m_CollectionLock.Execute(() => m_Collection.ToList(Count).GetEnumerator());
|
return m_Collection.GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ICollection.CopyTo(Array myArr, int index)
|
void ICollection.CopyTo(Array myArr, int index)
|
||||||
{
|
|
||||||
m_CollectionLock.Enter();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
foreach (TContents item in m_Collection)
|
foreach (TContents item in m_Collection)
|
||||||
{
|
{
|
||||||
@@ -156,11 +130,6 @@ namespace ICD.Common.Utils.Collections
|
|||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
m_CollectionLock.Leave();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -170,19 +139,10 @@ namespace ICD.Common.Utils.Collections
|
|||||||
/// Removes items that fall outside of the max size.
|
/// Removes items that fall outside of the max size.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void Trim()
|
private void Trim()
|
||||||
{
|
|
||||||
m_CollectionLock.Enter();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
while (Count > MaxSize)
|
while (Count > MaxSize)
|
||||||
m_Collection.RemoveFirst();
|
m_Collection.RemoveFirst();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
m_CollectionLock.Leave();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user