2003-01-24 Gonzalo Paniagua Javier <gonzalo@ximian.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Thu, 23 Jan 2003 23:59:51 +0000 (23:59 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Thu, 23 Jan 2003 23:59:51 +0000 (23:59 -0000)
* Enum.cs: added caching to GetInfo.

svn path=/trunk/mcs/; revision=10850

mcs/class/corlib/System/ChangeLog
mcs/class/corlib/System/Enum.cs

index 11ff5f8d3e70527c2d51e9741f28e41d6db2aad7..90c60c394dd2b95508d09d3cb448fcf551333012 100644 (file)
@@ -1,3 +1,7 @@
+2003-01-24  Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * Enum.cs: added caching to GetInfo.
+
 2003-01-23  Dick Porter  <dick@ximian.com>
 
        * Environment.cs (System): Implemented ExitCode
index 8c79c7f2b1fcca989f52005b134885b6306d76cf..76344b077e09501ffc0d6bb8ef75b1a16a7dac23 100644 (file)
@@ -19,17 +19,40 @@ namespace System {
                internal Type utype;
                internal Array values;
                internal string[] names;
+               static Hashtable cache;
                
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                private static extern void get_enum_info (Type enumType, out MonoEnumInfo info);
                
-               internal static void GetInfo (Type enumType, out MonoEnumInfo info) {
-                       get_enum_info (enumType, out info);
-                       Array.Sort (info.values, info.names);
+               private MonoEnumInfo (MonoEnumInfo other)
+               {
+                       utype = other.utype;
+                       values = other.values;
+                       names = other.names;
+               }
+               
+               internal static void GetInfo (Type enumType, out MonoEnumInfo info)
+               {
+                       if (cache == null) {
+                               cache = new Hashtable ();
+                       } else if (cache.ContainsKey (enumType)) {
+                               info = (MonoEnumInfo) cache [enumType];
+                               return;
+                       }
+
+                       lock (cache) {
+                               if (cache.ContainsKey (enumType)) {
+                                       info = (MonoEnumInfo) cache [enumType];
+                                       return;
+                               }
+
+                               get_enum_info (enumType, out info);
+                               Array.Sort (info.values, info.names);
+                               cache.Add (enumType, new MonoEnumInfo (info));
+                       }
                }
        };
 
-       [MonoTODO]
        public abstract class Enum : ValueType, IComparable, IConvertible, IFormattable {
 
                // IConvertible methods Start -->