From fad5e4bdeebf3a44a8b57ebcfb5dc21adce426f1 Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 18 Mar 2019 21:55:33 -0700 Subject: [PATCH] Expand comboitem loading for simple cases slightly less gc pressure, precompute capacity --- PKHeX.Core/Util/DataUtil.cs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/PKHeX.Core/Util/DataUtil.cs b/PKHeX.Core/Util/DataUtil.cs index 9136534fd..3fd6970a6 100644 --- a/PKHeX.Core/Util/DataUtil.cs +++ b/PKHeX.Core/Util/DataUtil.cs @@ -248,18 +248,29 @@ public static List GetUnsortedCBList(string textfile) .ToList(); } - public static List GetCBList(IReadOnlyList inStrings, params int[][] allowed) + public static List GetCBList(IReadOnlyList inStrings) { - if (allowed.Length == 0) - allowed = new[] { Enumerable.Range(0, inStrings.Count).ToArray() }; - - return allowed.SelectMany(list => list - .Select(z => new ComboItem { Text = inStrings[z], Value = z }) - .OrderBy(z => z.Text)) - .ToList(); + var list = new List(inStrings.Count); + var items = inStrings.Select((t, i) => new ComboItem {Text = t, Value = i}).OrderBy(z => z.Text); + list.AddRange(items); + return list; } - public static void AddCBWithOffset(List cbList, IReadOnlyList inStrings, int offset, IEnumerable allowed) + public static List GetCBList(IReadOnlyList inStrings, params int[][] allowed) + { + var count = allowed.Sum(z => z.Length); + var list = new List(count); + foreach (var arr in allowed) + { + var subset = arr + .Select(z => new ComboItem {Text = inStrings[z], Value = z}) + .OrderBy(z => z.Text); + list.AddRange(subset); + } + return list; + } + + public static void AddCBWithOffset(List cbList, IReadOnlyList inStrings, int offset, int[] allowed) { var list = allowed .Select(z => new ComboItem {Text = inStrings[z - offset], Value = z})