From 57b70684ea0f0cef981efac43faba54db63e49f5 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Sun, 19 May 2019 14:24:19 -0500 Subject: [PATCH] EnumHelper.get_values returns a cached strongly typed IReadOnlyList (simple optimization) --- src/client/spark/view/Utility/EnumHelper.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/client/spark/view/Utility/EnumHelper.cs b/src/client/spark/view/Utility/EnumHelper.cs index b2043831b..3fc0c8926 100644 --- a/src/client/spark/view/Utility/EnumHelper.cs +++ b/src/client/spark/view/Utility/EnumHelper.cs @@ -10,9 +10,11 @@ using System.Reflection; namespace mbts.ui.utility { static class EnumHelper { - public static IEnumerable get_values() { return Enum.GetValues(typeof(T)).Cast(); } + public static IReadOnlyList get_values() => + EnumDescriptorStore.values; - public static IEnumerable get_values_except(params T[] except) { return get_values().Except(except); } + public static IEnumerable get_values_except(params T[] except) => + get_values().Except(except); public static IEnumerable get_values(Type t) { if (!t.IsEnum) { @@ -115,6 +117,8 @@ namespace mbts.ui.utility { static class EnumDescriptorStore { public static readonly EnumDescriptor descriptor; + public static readonly IReadOnlyList values = Enum.GetValues(typeof(T)).Cast().ToReadOnlyList(); + static EnumDescriptorStore() { Func has_flags; if (!typeof(T).IsEnum) {