From b34e32199ff87e4b3d1508e0bb01c38af8f37865 Mon Sep 17 00:00:00 2001 From: Jack Freelander Date: Mon, 21 Mar 2016 13:19:43 -0700 Subject: [PATCH] Performance improvements for Enum.ToString() --- src/mscorlib/src/System/Enum.cs | 2 +- src/mscorlib/src/System/Type.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/mscorlib/src/System/Enum.cs b/src/mscorlib/src/System/Enum.cs index b0e3bf8f07e9..25cd8e87b2f6 100644 --- a/src/mscorlib/src/System/Enum.cs +++ b/src/mscorlib/src/System/Enum.cs @@ -137,7 +137,7 @@ private static String InternalFormat(RuntimeType eT, Object value) if (!eT.IsDefined(typeof(System.FlagsAttribute), false)) // Not marked with Flags attribute { // Try to see if its one of the enum values, then we return a String back else the value - String retval = GetName(eT, value); + String retval = eT.GetEnumName(value); if (retval == null) return value.ToString(); else diff --git a/src/mscorlib/src/System/Type.cs b/src/mscorlib/src/System/Type.cs index c6215d24c975..7d6878a81fba 100644 --- a/src/mscorlib/src/System/Type.cs +++ b/src/mscorlib/src/System/Type.cs @@ -1537,12 +1537,13 @@ public virtual string GetEnumName(object value) if (!(valueType.IsEnum || Type.IsIntegerType(valueType))) throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnumBaseTypeOrEnum"), "value"); - Array values = GetEnumRawConstantValues(); + string[] names; + Array values; + GetEnumData(out names, out values); int index = BinarySearch(values, value); if (index >= 0) { - string[] names = GetEnumNames(); return names[index]; }