From 1b6adc58f6c0c17cb535d93c2afefa87c29a2dff Mon Sep 17 00:00:00 2001 From: lindexi Date: Sat, 11 Jul 2020 11:48:17 +0800 Subject: [PATCH 1/2] Improve Deque initialization performance --- .../HandyControl_Shared/Tools/Queue/Deque!1.cs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/Shared/HandyControl_Shared/Tools/Queue/Deque!1.cs b/src/Shared/HandyControl_Shared/Tools/Queue/Deque!1.cs index d15c992c..cb44085f 100644 --- a/src/Shared/HandyControl_Shared/Tools/Queue/Deque!1.cs +++ b/src/Shared/HandyControl_Shared/Tools/Queue/Deque!1.cs @@ -65,19 +65,11 @@ namespace HandyControl.Tools public Deque(IEnumerable backCollection, IEnumerable frontCollection) { - if (backCollection == null && frontCollection == null) throw new ArgumentException("Collections cannot both be null"); - _front = new List(); - _back = new List(); + if (backCollection == null && frontCollection == null) + throw new ArgumentException("Collections cannot both be null"); - if (backCollection != null) - { - foreach (var item in backCollection) _back.Add(item); - } - - if (frontCollection != null) - { - foreach (var item in frontCollection) _front.Add(item); - } + _front = frontCollection != null ? new List(frontCollection) : new List(); + _back = backCollection != null ? new List(backCollection) : new List(); } public void AddFirst(T item) From 6cc25f892d1f7a07fa61bf02295e5a8e7def2037 Mon Sep 17 00:00:00 2001 From: lindexi Date: Sat, 11 Jul 2020 11:49:10 +0800 Subject: [PATCH 2/2] Format code --- src/Shared/HandyControl_Shared/Tools/Queue/Deque!1.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Shared/HandyControl_Shared/Tools/Queue/Deque!1.cs b/src/Shared/HandyControl_Shared/Tools/Queue/Deque!1.cs index cb44085f..af1aaf1f 100644 --- a/src/Shared/HandyControl_Shared/Tools/Queue/Deque!1.cs +++ b/src/Shared/HandyControl_Shared/Tools/Queue/Deque!1.cs @@ -65,8 +65,7 @@ namespace HandyControl.Tools public Deque(IEnumerable backCollection, IEnumerable frontCollection) { - if (backCollection == null && frontCollection == null) - throw new ArgumentException("Collections cannot both be null"); + if (backCollection == null && frontCollection == null) throw new ArgumentException("Collections cannot both be null"); _front = frontCollection != null ? new List(frontCollection) : new List(); _back = backCollection != null ? new List(backCollection) : new List();