From 53ecc83a5a5dc3a2c2b65226a5af94a7a38cbbee Mon Sep 17 00:00:00 2001 From: status102 <102887808+status102@users.noreply.github.com> Date: Sun, 25 Feb 2024 16:48:39 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=88=98=E6=96=97-=E5=B9=B2=E5=91=98=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=AD=A3=E5=88=99=E5=8F=8Ajarry=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [skip changelog] --- src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs b/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs index 37a178f557..a62bbca703 100644 --- a/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs @@ -928,17 +928,13 @@ namespace MaaWpfGui.ViewModels.UI AddLog(errMsg, UiLogColor.Error); } - JArray mUserAdditional = new JArray(); - Regex regex = new Regex(@"(?<=;)(?[^,;]+)(?:, *(?\d))? *", RegexOptions.Compiled); - MatchCollection matches = regex.Matches(";" + UserAdditional.Replace(",", ",").Replace(";", ";")); - foreach (Match match in matches) + UserAdditional = UserAdditional.Replace(",", ",").Replace(";", ";").Trim(); + Regex regex = new Regex(@"(?<=;)(?[^,;]+)(?:, *(?\d))?(?=;)", RegexOptions.Compiled); + JArray mUserAdditional = new(regex.Matches(";" + UserAdditional + ";").ToList().Select(match => new JObject { - mUserAdditional.Add(new JObject - { - ["name"] = match.Groups[1].Value.Trim(), - ["skill"] = string.IsNullOrEmpty(match.Groups[2].Value) ? 0 : int.Parse(match.Groups[2].Value), - }); - } + ["name"] = match.Groups[1].Value.Trim(), + ["skill"] = string.IsNullOrEmpty(match.Groups[2].Value) ? 0 : int.Parse(match.Groups[2].Value), + })); bool ret = true; if (UseCopilotList)