Improve Deque initialization performance

This commit is contained in:
lindexi committed 2020-07-11 11:48:17 +08:00
1 parent cb546c1896
commit 1b6adc58f6
1 file changed
+4 -12
@@ -65,19 +65,11 @@ namespace HandyControl.Tools
public Deque(IEnumerable<T> backCollection, IEnumerable<T> frontCollection) public Deque(IEnumerable<T> backCollection, IEnumerable<T> frontCollection)
{ {
if (backCollection == null && frontCollection == null) throw new ArgumentException("Collections cannot both be null"); if (backCollection == null && frontCollection == null)
_front = new List<T>(); throw new ArgumentException("Collections cannot both be null");
_back = new List<T>();
if (backCollection != null) _front = frontCollection != null ? new List<T>(frontCollection) : new List<T>();
{ _back = backCollection != null ? new List<T>(backCollection) : new List<T>();
foreach (var item in backCollection) _back.Add(item);
}
if (frontCollection != null)
{
foreach (var item in frontCollection) _front.Add(item);
}
} }
public void AddFirst(T item) public void AddFirst(T item)