Browse Source

Clean up some static initializers

Marek Safar 13 years ago
parent
commit
7883a2dafd
41 changed files with 173 additions and 222 deletions
  1. 2 2
      mcs/class/corlib/Mono.Security.Cryptography/KeyPairPersistence.cs
  2. 1 1
      mcs/class/corlib/Mono.Security.X509/PKCS12.cs
  3. 1 3
      mcs/class/corlib/Mono.Security.X509/X509Certificate.cs
  4. 1 1
      mcs/class/corlib/Mono.Security/StrongName.cs
  5. 0 4
      mcs/class/corlib/Mono.Security/StrongNameManager.cs
  6. 2 3
      mcs/class/corlib/System.Collections.Generic/List.cs
  7. 2 4
      mcs/class/corlib/System.Collections/ArrayList.cs
  8. 2 2
      mcs/class/corlib/System.Collections/CaseInsensitiveComparer.cs
  9. 1 1
      mcs/class/corlib/System.Collections/Hashtable.cs
  10. 2 2
      mcs/class/corlib/System.Collections/SortedList.cs
  11. 1 1
      mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFile.cs
  12. 3 3
      mcs/class/corlib/System.IO/MonoIO.cs
  13. 1 8
      mcs/class/corlib/System.Reflection.Emit/EventToken.cs
  14. 1 8
      mcs/class/corlib/System.Reflection.Emit/FieldToken.cs
  15. 2 3
      mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs
  16. 1 8
      mcs/class/corlib/System.Reflection.Emit/MethodToken.cs
  17. 1 1
      mcs/class/corlib/System.Reflection.Emit/OpCodeNames.cs
  18. 1 8
      mcs/class/corlib/System.Reflection.Emit/ParameterToken.cs
  19. 1 8
      mcs/class/corlib/System.Reflection.Emit/PropertyToken.cs
  20. 1 8
      mcs/class/corlib/System.Reflection.Emit/SignatureToken.cs
  21. 0 5
      mcs/class/corlib/System.Reflection.Emit/StringToken.cs
  22. 1 8
      mcs/class/corlib/System.Reflection.Emit/TypeToken.cs
  23. 1 1
      mcs/class/corlib/System.Reflection/Binder.cs
  24. 2 8
      mcs/class/corlib/System.Reflection/Module.cs
  25. 2 2
      mcs/class/corlib/System.Resources/ResourceManager.cs
  26. 1 6
      mcs/class/corlib/System.Runtime.InteropServices/ExtensibleClassFactory.cs
  27. 1 6
      mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs
  28. 3 3
      mcs/class/corlib/System.Text/DecoderFallback.cs
  29. 3 3
      mcs/class/corlib/System.Text/EncoderFallback.cs
  30. 3 5
      mcs/class/corlib/System.Text/Encoding.cs
  31. 1 1
      mcs/class/corlib/System.Text/UTF32Encoding.cs
  32. 1 1
      mcs/class/corlib/System.Text/UTF8Encoding.cs
  33. 1 1
      mcs/class/corlib/System.Text/UnicodeEncoding.cs
  34. 1 1
      mcs/class/corlib/System.Threading/SpinLock.cs
  35. 1 1
      mcs/class/corlib/System.Threading/Timer.cs
  36. 35 0
      mcs/class/corlib/System/EmptyArray.cs
  37. 6 10
      mcs/class/corlib/System/Enum.cs
  38. 1 3
      mcs/class/corlib/System/MonoCustomAttrs.cs
  39. 12 9
      mcs/class/corlib/System/StringComparer.cs
  40. 69 69
      mcs/class/corlib/System/TermInfoDriver.cs
  41. 1 0
      mcs/class/corlib/corlib.dll.sources

+ 2 - 2
mcs/class/corlib/Mono.Security.Cryptography/KeyPairPersistence.cs

@@ -100,10 +100,10 @@ namespace Mono.Security.Cryptography {
 #endif
 	class KeyPairPersistence {
 	
-		private static bool _userPathExists = false; // check at 1st use
+		private static bool _userPathExists; // check at 1st use
 		private static string _userPath;
 		
-		private static bool _machinePathExists = false; // check at 1st use
+		private static bool _machinePathExists; // check at 1st use
 		private static string _machinePath;
 
 		private CspParameters _params;

+ 1 - 1
mcs/class/corlib/Mono.Security.X509/PKCS12.cs

@@ -265,7 +265,7 @@ namespace Mono.Security.X509 {
 			}
 		}
 
-		static private int recommendedIterationCount = 2000;
+		const int recommendedIterationCount = 2000;
 
 		//private int _version;
 		private byte[] _password;

+ 1 - 3
mcs/class/corlib/Mono.Security.X509/X509Certificate.cs

@@ -49,6 +49,7 @@ namespace Mono.Security.X509 {
 #else
 	public class X509Certificate : ISerializable {
 #endif
+		const string encoding_error = "Input data cannot be coded as a valid certificate.";
 
 		private ASN1 decoder;
 
@@ -97,9 +98,6 @@ namespace Mono.Security.X509 {
 		private byte[] subjectUniqueID;
 		private X509ExtensionCollection extensions;
 
-		private static string encoding_error = Locale.GetText ("Input data cannot be coded as a valid certificate.");
-
-
 		// that's were the real job is!
 		private void Parse (byte[] data) 
 		{

+ 1 - 1
mcs/class/corlib/Mono.Security/StrongName.cs

@@ -459,7 +459,7 @@ namespace Mono.Security {
 
 #if INSIDE_CORLIB
 		static object lockObject = new object ();
-		static bool initialized = false;
+		static bool initialized;
 
 		// We don't want a dependency on StrongNameManager in Mono.Security.dll
 		static public bool IsAssemblyStrongnamed (string assemblyName) 

+ 0 - 4
mcs/class/corlib/Mono.Security/StrongNameManager.cs

@@ -101,10 +101,6 @@ namespace Mono.Security {
 		static private Hashtable mappings;
 		static private Hashtable tokens;
 
-		static StrongNameManager () 
-		{
-		}
-
 		// note: more than one configuration file can be loaded at the 
 		// same time (e.g. user specific and machine specific config).
 		static public void LoadConfig (string filename) 

+ 2 - 3
mcs/class/corlib/System.Collections.Generic/List.cs

@@ -50,12 +50,11 @@ namespace System.Collections.Generic {
 		int _size;
 		int _version;
 		
-		static readonly T [] EmptyArray = new T [0]; 
 		const int DefaultCapacity = 4;
 		
 		public List ()
 		{
-			_items = EmptyArray;
+			_items = EmptyArray<T>.Value;
 		}
 		
 		public List (IEnumerable <T> collection)
@@ -66,7 +65,7 @@ namespace System.Collections.Generic {
 			// initialize to needed size (if determinable)
 			ICollection <T> c = collection as ICollection <T>;
 			if (c == null) {
-				_items = EmptyArray;
+				_items = EmptyArray<T>.Value;;
 				AddEnumerable (collection);
 			} else {
 				_size = c.Count;

+ 2 - 4
mcs/class/corlib/System.Collections/ArrayList.cs

@@ -115,7 +115,7 @@ namespace System.Collections
 			object currentElement;
 			int index;
 			int version;
-			static object endFlag = new object ();
+			static readonly object endFlag = new object ();
 							
 			public SimpleEnumerator (ArrayList list)
 			{
@@ -2510,8 +2510,6 @@ namespace System.Collections
 		/// </summary>
 		private int _version;
 
-		private static readonly object [] EmptyArray = new object [0]; 
-
 		#endregion
 		
 		#region Constructors
@@ -2522,7 +2520,7 @@ namespace System.Collections
 		/// </summary>
 		public ArrayList()
 		{
-			_items = EmptyArray;
+			_items = EmptyArray<object>.Value;
 		}		
 
 		/// <summary>

+ 2 - 2
mcs/class/corlib/System.Collections/CaseInsensitiveComparer.cs

@@ -44,8 +44,8 @@ namespace System.Collections
 #endif
 	class CaseInsensitiveComparer : IComparer
 	{
-		private static CaseInsensitiveComparer defaultComparer = new CaseInsensitiveComparer ();
-		private static CaseInsensitiveComparer defaultInvariantComparer = new CaseInsensitiveComparer (true);
+		readonly static CaseInsensitiveComparer defaultComparer = new CaseInsensitiveComparer ();
+		readonly static CaseInsensitiveComparer defaultInvariantComparer = new CaseInsensitiveComparer (true);
 
 		private CultureInfo culture;
 

+ 1 - 1
mcs/class/corlib/System.Collections/Hashtable.cs

@@ -864,7 +864,7 @@ namespace System.Collections {
 			private int size;
 			private EnumeratorMode mode;
 
-			private readonly static string xstr = "Hashtable.Enumerator: snapshot out of sync.";
+			const string xstr = "Hashtable.Enumerator: snapshot out of sync.";
 
 			public Enumerator (Hashtable host, EnumeratorMode mode) {
 				this.host = host;

+ 2 - 2
mcs/class/corlib/System.Collections/SortedList.cs

@@ -618,9 +618,9 @@ namespace System.Collections {
 			private int size;
 			private EnumeratorMode mode;
 
-			bool invalid = false;
+			bool invalid;
 
-			private readonly static string xstr = "SortedList.Enumerator: snapshot out of sync.";
+			const string xstr = "SortedList.Enumerator: snapshot out of sync.";
 
 			public Enumerator (SortedList host, EnumeratorMode mode)
 			{

+ 1 - 1
mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFile.cs

@@ -56,7 +56,7 @@ namespace System.IO.IsolatedStorage {
 		private ulong _maxSize;
 #endif
 		private Evidence _fullEvidences;
-		private static Mutex mutex = new Mutex ();
+		private static readonly Mutex mutex = new Mutex ();
 #if NET_4_0 || MOBILE
 		private bool closed;
 		private bool disposed;

+ 3 - 3
mcs/class/corlib/System.IO/MonoIO.cs

@@ -41,10 +41,10 @@ using System.IO.IsolatedStorage;
 
 namespace System.IO
 {
-	unsafe internal sealed class MonoIO {
-		internal static int FileAlreadyExistsHResult = unchecked ((int) 0x80070000) | (int)MonoIOError.ERROR_FILE_EXISTS;
+	unsafe static class MonoIO {
+		public const int FileAlreadyExistsHResult = unchecked ((int) 0x80070000) | (int)MonoIOError.ERROR_FILE_EXISTS;
 
-		public static readonly FileAttributes
+		public const FileAttributes
 			InvalidFileAttributes = (FileAttributes)(-1);
 
 		public static readonly IntPtr

+ 1 - 8
mcs/class/corlib/System.Reflection.Emit/EventToken.cs

@@ -39,14 +39,7 @@ namespace System.Reflection.Emit {
 
 		internal int tokValue;
 
-		public static readonly EventToken Empty;
-
-
-		static EventToken ()
-		{
-			Empty = new EventToken ();
-		}
-
+		public static readonly EventToken Empty = new EventToken ();
 
 		internal EventToken (int val)
 		{

+ 1 - 8
mcs/class/corlib/System.Reflection.Emit/FieldToken.cs

@@ -39,14 +39,7 @@ namespace System.Reflection.Emit {
 
 		internal int tokValue;
 
-		public static readonly FieldToken Empty;
-
-
-		static FieldToken ()
-		{
-			Empty = new FieldToken ();
-		}
-
+		public static readonly FieldToken Empty = new FieldToken ();
 
 		internal FieldToken (int val)
 		{

+ 2 - 3
mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs

@@ -207,7 +207,6 @@ namespace System.Reflection.Emit {
 			public int maxStack; 
 		}
 		
-		static readonly Type void_type = typeof (void);
 		#region Sync with reflection.h
 		private byte[] code;
 		private int code_len;
@@ -740,7 +739,7 @@ namespace System.Reflection.Emit {
 					add_token_fixup (meth);
 			}
 			emit_int (token);
-			if (meth.ReturnType != void_type)
+			if (meth.ReturnType != typeof (void))
 				cur_stack ++;
 
 			if (opcode.StackBehaviourPop == StackBehaviour.Varpop)
@@ -758,7 +757,7 @@ namespace System.Reflection.Emit {
 					add_token_fixup (method);
 			}
 			emit_int (token);
-			if (method.ReturnType != void_type)
+			if (method.ReturnType != typeof (void))
 				cur_stack ++;
 
 			if (opcode.StackBehaviourPop == StackBehaviour.Varpop)

+ 1 - 8
mcs/class/corlib/System.Reflection.Emit/MethodToken.cs

@@ -39,14 +39,7 @@ namespace System.Reflection.Emit {
 
 		internal int tokValue;
 
-		public static readonly MethodToken Empty;
-
-
-		static MethodToken ()
-		{
-			Empty = new MethodToken ();
-		}
-
+		public static readonly MethodToken Empty = new MethodToken ();
 
 		internal MethodToken (int val)
 		{

+ 1 - 1
mcs/class/corlib/System.Reflection.Emit/OpCodeNames.cs

@@ -1,5 +1,5 @@
 namespace System.Reflection.Emit {
-	internal class OpCodeNames {
+	static class OpCodeNames {
 		internal static readonly string [] names = {
 			"nop",
 			"break",

+ 1 - 8
mcs/class/corlib/System.Reflection.Emit/ParameterToken.cs

@@ -39,14 +39,7 @@ namespace System.Reflection.Emit {
 
 		internal int tokValue;
 
-		public static readonly ParameterToken Empty;
-
-
-		static ParameterToken ()
-		{
-			Empty = new ParameterToken ();
-		}
-
+		public static readonly ParameterToken Empty = new ParameterToken ();
 
 		internal ParameterToken (int val)
 		{

+ 1 - 8
mcs/class/corlib/System.Reflection.Emit/PropertyToken.cs

@@ -39,14 +39,7 @@ namespace System.Reflection.Emit {
 
 		internal int tokValue;
 
-		public static readonly PropertyToken Empty;
-
-
-		static PropertyToken ()
-		{
-			Empty = new PropertyToken ();
-		}
-
+		public static readonly PropertyToken Empty = new PropertyToken ();
 
 		internal PropertyToken (int val)
 		{

+ 1 - 8
mcs/class/corlib/System.Reflection.Emit/SignatureToken.cs

@@ -38,14 +38,7 @@ namespace System.Reflection.Emit {
 
 		internal int tokValue;
 
-		public static readonly SignatureToken Empty;
-
-
-		static SignatureToken ()
-		{
-			Empty = new SignatureToken ();
-		}
-
+		public static readonly SignatureToken Empty = new SignatureToken ();
 
 		internal SignatureToken (int val)
 		{

+ 0 - 5
mcs/class/corlib/System.Reflection.Emit/StringToken.cs

@@ -39,11 +39,6 @@ namespace System.Reflection.Emit {
 
 		internal int tokValue;
 
-		static StringToken ()
-		{
-		}
-
-
 		internal StringToken (int val)
 		{
 			tokValue = val;

+ 1 - 8
mcs/class/corlib/System.Reflection.Emit/TypeToken.cs

@@ -39,14 +39,7 @@ namespace System.Reflection.Emit {
 
 		internal int tokValue;
 
-		public static readonly TypeToken Empty;
-
-
-		static TypeToken ()
-		{
-			Empty = new TypeToken ();
-		}
-
+		public static readonly TypeToken Empty = new TypeToken ();
 
 		internal TypeToken (int val)
 		{

+ 1 - 1
mcs/class/corlib/System.Reflection/Binder.cs

@@ -50,7 +50,7 @@ namespace System.Reflection
 		public abstract MethodBase SelectMethod (BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers);
 		public abstract PropertyInfo SelectProperty( BindingFlags bindingAttr, PropertyInfo[] match, Type returnType, Type[] indexes, ParameterModifier[] modifiers);
 
-		static Binder default_binder = new Default ();
+		static readonly Binder default_binder = new Default ();
 
 		internal static Binder DefaultBinder {
 			get {

+ 2 - 8
mcs/class/corlib/System.Reflection/Module.cs

@@ -53,8 +53,8 @@ namespace System.Reflection {
 #else
 	public partial class Module : ISerializable, ICustomAttributeProvider, _Module {
 #endif
-		public static readonly TypeFilter FilterTypeName;
-		public static readonly TypeFilter FilterTypeNameIgnoreCase;
+		public static readonly TypeFilter FilterTypeName = new TypeFilter (filter_by_type_name);
+		public static readonly TypeFilter FilterTypeNameIgnoreCase = new TypeFilter (filter_by_type_name_ignore_case);
 	
 #pragma warning disable 649	
 		internal IntPtr _impl; /* a pointer to a MonoImage */
@@ -68,12 +68,6 @@ namespace System.Reflection {
 	
 		const BindingFlags defaultBindingFlags = 
 			BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
-		
-		static Module () {
-			FilterTypeName = new TypeFilter (filter_by_type_name);
-			FilterTypeNameIgnoreCase = new TypeFilter (filter_by_type_name_ignore_case);
-		}
-
 
 #if NET_4_0 || MOONLIGHT || MOBILE
 		protected

+ 2 - 2
mcs/class/corlib/System.Resources/ResourceManager.cs

@@ -45,8 +45,8 @@ namespace System.Resources
 	public class ResourceManager
 	{
 		static readonly object thisLock = new object ();
-		static Hashtable ResourceCache = new Hashtable (); 
-		static Hashtable NonExistent = Hashtable.Synchronized (new Hashtable ());
+		static readonly Hashtable ResourceCache = new Hashtable (); 
+		static readonly Hashtable NonExistent = Hashtable.Synchronized (new Hashtable ());
 		public static readonly int HeaderVersionNumber = 1;
 		public static readonly int MagicNumber = unchecked ((int) 0xBEEFCACE);
 

+ 1 - 6
mcs/class/corlib/System.Runtime.InteropServices/ExtensibleClassFactory.cs

@@ -39,12 +39,7 @@ namespace System.Runtime.InteropServices
 	[ComVisible (true)]
 	public sealed class ExtensibleClassFactory
 	{
-		static Hashtable hashtable;
-
-		static ExtensibleClassFactory ()
-		{
-			hashtable = new Hashtable ();
-		}
+		static readonly Hashtable hashtable = new Hashtable ();
 
 		private ExtensibleClassFactory ()
 		{

+ 1 - 6
mcs/class/corlib/System.Runtime.InteropServices/Marshal.cs

@@ -52,12 +52,7 @@ namespace System.Runtime.InteropServices
 	{
 		/* fields */
 		public static readonly int SystemMaxDBCSCharSize = 2; // don't know what this is
-		public static readonly int SystemDefaultCharSize;
-
-		static Marshal ()
-		{
-			SystemDefaultCharSize = Environment.OSVersion.Platform == PlatformID.Win32NT ? 2 : 1;
-		}
+		public static readonly int SystemDefaultCharSize = Environment.OSVersion.Platform == PlatformID.Win32NT ? 2 : 1;
 
 		[MethodImplAttribute (MethodImplOptions.InternalCall)]
 		private extern static int AddRefInternal (IntPtr pUnk);

+ 3 - 3
mcs/class/corlib/System.Text/DecoderFallback.cs

@@ -33,11 +33,11 @@ namespace System.Text
 	[Serializable]
 	public abstract class DecoderFallback
 	{
-		static DecoderFallback exception_fallback =
+		static readonly DecoderFallback exception_fallback =
 			new DecoderExceptionFallback ();
-		static DecoderFallback replacement_fallback =
+		static readonly DecoderFallback replacement_fallback =
 			new DecoderReplacementFallback ();
-		static DecoderFallback standard_safe_fallback =
+		static readonly DecoderFallback standard_safe_fallback =
 			new DecoderReplacementFallback ("\uFFFD");
 
 		protected DecoderFallback ()

+ 3 - 3
mcs/class/corlib/System.Text/EncoderFallback.cs

@@ -33,11 +33,11 @@ namespace System.Text
 	[Serializable]
 	public abstract class EncoderFallback
 	{
-		static EncoderFallback exception_fallback =
+		static readonly EncoderFallback exception_fallback =
 			new EncoderExceptionFallback ();
-		static EncoderFallback replacement_fallback =
+		static readonly EncoderFallback replacement_fallback =
 			new EncoderReplacementFallback ();
-		static EncoderFallback standard_safe_fallback =
+		static readonly EncoderFallback standard_safe_fallback =
 			new EncoderReplacementFallback ("\uFFFD");
 
 		protected EncoderFallback ()

+ 3 - 5
mcs/class/corlib/System.Text/Encoding.cs

@@ -42,8 +42,6 @@ public abstract class Encoding : ICloneable
 	internal int codePage;
 	internal int windows_code_page;
 	bool is_readonly = true;
-	
-	internal static readonly byte[] empty = new byte[0];
 
 	// Constructor.
 	protected Encoding ()
@@ -246,10 +244,10 @@ public abstract class Encoding : ICloneable
 			throw new ArgumentNullException ("s");
 
 		if (s.Length == 0)
-			return empty;
+			return EmptyArray<byte>.Value;
 		int byteCount = GetByteCount (s);
 		if (byteCount == 0)
-			return empty;
+			return EmptyArray<byte>.Value;
 		unsafe {
 			fixed (char* cptr = s) {
 				byte [] bytes = new byte [byteCount];
@@ -697,7 +695,7 @@ public abstract class Encoding : ICloneable
 	// Get the identifying preamble for this encoding.
 	public virtual byte[] GetPreamble ()
 	{
-		return empty;
+		return EmptyArray<byte>.Value;
 	}
 
 	// Decode a buffer of bytes into a string.

+ 1 - 1
mcs/class/corlib/System.Text/UTF32Encoding.cs

@@ -316,7 +316,7 @@ public sealed class UTF32Encoding : Encoding
 			return preamble;
 		}
 		
-		return empty;
+		return EmptyArray<byte>.Value;
 	}
 
 	// Determine if this object is equal to another.

+ 1 - 1
mcs/class/corlib/System.Text/UTF8Encoding.cs

@@ -879,7 +879,7 @@ fail_no_space:
 		if (emitIdentifier)
 			return new byte [] { 0xEF, 0xBB, 0xBF };
 
-		return empty;
+		return EmptyArray<byte>.Value;
 	}
 
 	// Determine if this object is equal to another.

+ 1 - 1
mcs/class/corlib/System.Text/UnicodeEncoding.cs

@@ -380,7 +380,7 @@ public class UnicodeEncoding : Encoding
 			return preamble;
 		}
 		
-		return empty;
+		return EmptyArray<byte>.Value;
 	}
 
 	// Determine if this object is equal to another.

+ 1 - 1
mcs/class/corlib/System.Threading/SpinLock.cs

@@ -57,7 +57,7 @@ namespace System.Threading
 		int threadWhoTookLock;
 		readonly bool isThreadOwnerTrackingEnabled;
 
-		static Watch sw = Watch.StartNew ();
+		static readonly Watch sw = Watch.StartNew ();
 
 		ConcurrentOrderedList<int> stallTickets;
 

+ 1 - 1
mcs/class/corlib/System.Threading/Timer.cs

@@ -41,7 +41,7 @@ namespace System.Threading
 		: MarshalByRefObject, IDisposable
 #endif
 	{
-		static Scheduler scheduler = Scheduler.Instance;
+		static readonly Scheduler scheduler = Scheduler.Instance;
 #region Timer instance fields
 		TimerCallback callback;
 		object state;

+ 35 - 0
mcs/class/corlib/System/EmptyArray.cs

@@ -0,0 +1,35 @@
+//
+// EmptyArray.cs
+//
+// Authors:
+//	Marek Safar  <[email protected]>
+//
+// Copyright (C) 2012 Xamarin, Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+namespace System
+{
+	static class EmptyArray<T>
+	{
+		public static readonly T[] Value = new T [0];
+	}
+}

+ 6 - 10
mcs/class/corlib/System/Enum.cs

@@ -48,8 +48,8 @@ namespace System
 		internal Hashtable name_hash;
 		[ThreadStatic]
 		static Hashtable cache;
-		static Hashtable global_cache;
-		static object global_cache_monitor;
+		static Hashtable global_cache = new Hashtable ();
+		static object global_cache_monitor = new object ();
 		
 		[MethodImplAttribute (MethodImplOptions.InternalCall)]
 		private static extern void get_enum_info (Type enumType, out MonoEnumInfo info);
@@ -145,12 +145,6 @@ namespace System
 				return 1;
 			}
 		}
-			
-		static MonoEnumInfo ()
-		{
-			global_cache_monitor = new object ();
-			global_cache = new Hashtable ();
-		}
 
 		static Hashtable Cache {
 			get {
@@ -512,8 +506,6 @@ namespace System
 			throw new ArgumentException ("typeCode is not a valid type code for an Enum");
 		}
 
-		private static char [] split_char = { ',' };
-
 		[ComVisible(true)]
 		public static object Parse (Type enumType, string value, bool ignoreCase)
 		{
@@ -537,6 +529,8 @@ namespace System
 			return result;
 		}
 
+		static char [] split_char;
+
 		static bool Parse<TEnum> (Type enumType, string value, bool ignoreCase, out TEnum result)
 		{
 			result = default (TEnum);
@@ -555,6 +549,8 @@ namespace System
 
 			// is 'value' a list of named constants?
 			if (value.IndexOf (',') != -1) {
+				if (split_char == null)
+					split_char = new [] { ',' };
 				string [] names = value.Split (split_char);
 				ulong retVal = 0;
 				for (int i = 0; i < names.Length; ++i) {

+ 1 - 3
mcs/class/corlib/System/MonoCustomAttrs.cs

@@ -402,8 +402,7 @@ namespace System
 				return new AttributeUsageAttribute (AttributeTargets.Class);
 
 			AttributeUsageAttribute usageAttribute = null;
-			object[] attribs = GetCustomAttributes (attributeType,
-				MonoCustomAttrs.AttributeUsageType, false);
+			object[] attribs = GetCustomAttributes (attributeType, typeof(AttributeUsageAttribute), false);
 			if (attribs.Length == 0)
 			{
 				// if no AttributeUsage was defined on the attribute level, then
@@ -435,7 +434,6 @@ namespace System
 			return ((AttributeUsageAttribute) attribs[0]);
 		}
 
-		private static readonly Type AttributeUsageType = typeof(AttributeUsageAttribute);
 		private static readonly AttributeUsageAttribute DefaultAttributeUsage =
 			new AttributeUsageAttribute (AttributeTargets.All);
 

+ 12 - 9
mcs/class/corlib/System/StringComparer.cs

@@ -37,11 +37,14 @@ namespace System
 	[Serializable, ComVisible(true)]
 	public abstract class StringComparer : IComparer, IEqualityComparer, IComparer<string>, IEqualityComparer<string>
 	{
-		static StringComparer invariantCultureIgnoreCase = new CultureAwareComparer (CultureInfo.InvariantCulture, true);
-		static StringComparer invariantCulture = new CultureAwareComparer (CultureInfo.InvariantCulture, false);
-		static StringComparer ordinalIgnoreCase = new OrdinalComparer (true);
-		static StringComparer ordinal = new OrdinalComparer (false);
-
+		static class Predefined
+		{
+			public static readonly StringComparer invariantCultureIgnoreCase = new CultureAwareComparer (CultureInfo.InvariantCulture, true);
+			public static readonly StringComparer invariantCulture = new CultureAwareComparer (CultureInfo.InvariantCulture, false);
+			public static readonly StringComparer ordinalIgnoreCase = new OrdinalComparer (true);
+			public static readonly StringComparer ordinal = new OrdinalComparer (false);
+		}
+		
 		// Constructors
 		protected StringComparer ()
 		{
@@ -62,22 +65,22 @@ namespace System
 
 		public static StringComparer InvariantCulture {
 			get {
-				return invariantCulture;
+				return Predefined.invariantCulture;
 			}
 		}
 
 		public static StringComparer InvariantCultureIgnoreCase {
 			get {
-				return invariantCultureIgnoreCase;
+				return Predefined.invariantCultureIgnoreCase;
 			}
 		}
 
 		public static StringComparer Ordinal {
-			get { return ordinal; }
+			get { return Predefined.ordinal; }
 		}
 
 		public static StringComparer OrdinalIgnoreCase {
-			get { return ordinalIgnoreCase; }
+			get { return Predefined.ordinalIgnoreCase; }
 		}
 
 		// Methods

+ 69 - 69
mcs/class/corlib/System/TermInfoDriver.cs

@@ -47,7 +47,7 @@ namespace System {
 		static int terminal_size;
 		
 		//static uint flag = 0xdeadbeef;
-		static string [] locations = { "/etc/terminfo", "/usr/share/terminfo", "/usr/lib/terminfo" };
+		readonly static string [] locations = { "/etc/terminfo", "/usr/share/terminfo", "/usr/lib/terminfo" };
 
 		TermInfoReader reader;
 		int cursorLeft;
@@ -1325,74 +1325,6 @@ namespace System {
 			keymap [TermInfoStrings.KeyIc] = new ConsoleKeyInfo ('\0', ConsoleKey.Insert, false, false, false);
 		}
 
-		//
-		// The keys that we know about and use
-		//
-		static TermInfoStrings [] UsedKeys = {
-			TermInfoStrings.KeyBackspace,
-			TermInfoStrings.KeyClear,
-			TermInfoStrings.KeyDown,
-			TermInfoStrings.KeyF1,
-			TermInfoStrings.KeyF10,
-			TermInfoStrings.KeyF2,
-			TermInfoStrings.KeyF3,
-			TermInfoStrings.KeyF4,
-			TermInfoStrings.KeyF5,
-			TermInfoStrings.KeyF6,
-			TermInfoStrings.KeyF7,
-			TermInfoStrings.KeyF8,
-			TermInfoStrings.KeyF9,
-			TermInfoStrings.KeyHome,
-			TermInfoStrings.KeyLeft,
-			TermInfoStrings.KeyLl,
-			TermInfoStrings.KeyNpage,
-			TermInfoStrings.KeyPpage,
-			TermInfoStrings.KeyRight,
-			TermInfoStrings.KeySf,
-			TermInfoStrings.KeySr,
-			TermInfoStrings.KeyUp,
-			TermInfoStrings.KeyA1,
-			TermInfoStrings.KeyA3,
-			TermInfoStrings.KeyB2,
-			TermInfoStrings.KeyC1,
-			TermInfoStrings.KeyC3,
-			TermInfoStrings.KeyBtab,
-			TermInfoStrings.KeyBeg,
-			TermInfoStrings.KeyCopy,
-			TermInfoStrings.KeyEnd,
-			TermInfoStrings.KeyEnter,
-			TermInfoStrings.KeyHelp,
-			TermInfoStrings.KeyPrint,
-			TermInfoStrings.KeyUndo,
-			TermInfoStrings.KeySbeg,
-			TermInfoStrings.KeyScopy,
-			TermInfoStrings.KeySdc,
-			TermInfoStrings.KeyShelp,
-			TermInfoStrings.KeyShome,
-			TermInfoStrings.KeySleft,
-			TermInfoStrings.KeySprint,
-			TermInfoStrings.KeySright,
-			TermInfoStrings.KeySundo,
-			TermInfoStrings.KeyF11,
-			TermInfoStrings.KeyF12,
-			TermInfoStrings.KeyF13,
-			TermInfoStrings.KeyF14,
-			TermInfoStrings.KeyF15,
-			TermInfoStrings.KeyF16,
-			TermInfoStrings.KeyF17,
-			TermInfoStrings.KeyF18,
-			TermInfoStrings.KeyF19,
-			TermInfoStrings.KeyF20,
-			TermInfoStrings.KeyF21,
-			TermInfoStrings.KeyF22,
-			TermInfoStrings.KeyF23,
-			TermInfoStrings.KeyF24,
-
-			// These were missing
-			TermInfoStrings.KeyDc,
-			TermInfoStrings.KeyIc
-		};
-		
 		void InitKeys ()
 		{
 			if (initKeys)
@@ -1401,6 +1333,74 @@ namespace System {
 			CreateKeyMap ();
 			rootmap = new ByteMatcher ();
 
+			//
+			// The keys that we know about and use
+			//
+			var UsedKeys = new [] {
+				TermInfoStrings.KeyBackspace,
+				TermInfoStrings.KeyClear,
+				TermInfoStrings.KeyDown,
+				TermInfoStrings.KeyF1,
+				TermInfoStrings.KeyF10,
+				TermInfoStrings.KeyF2,
+				TermInfoStrings.KeyF3,
+				TermInfoStrings.KeyF4,
+				TermInfoStrings.KeyF5,
+				TermInfoStrings.KeyF6,
+				TermInfoStrings.KeyF7,
+				TermInfoStrings.KeyF8,
+				TermInfoStrings.KeyF9,
+				TermInfoStrings.KeyHome,
+				TermInfoStrings.KeyLeft,
+				TermInfoStrings.KeyLl,
+				TermInfoStrings.KeyNpage,
+				TermInfoStrings.KeyPpage,
+				TermInfoStrings.KeyRight,
+				TermInfoStrings.KeySf,
+				TermInfoStrings.KeySr,
+				TermInfoStrings.KeyUp,
+				TermInfoStrings.KeyA1,
+				TermInfoStrings.KeyA3,
+				TermInfoStrings.KeyB2,
+				TermInfoStrings.KeyC1,
+				TermInfoStrings.KeyC3,
+				TermInfoStrings.KeyBtab,
+				TermInfoStrings.KeyBeg,
+				TermInfoStrings.KeyCopy,
+				TermInfoStrings.KeyEnd,
+				TermInfoStrings.KeyEnter,
+				TermInfoStrings.KeyHelp,
+				TermInfoStrings.KeyPrint,
+				TermInfoStrings.KeyUndo,
+				TermInfoStrings.KeySbeg,
+				TermInfoStrings.KeyScopy,
+				TermInfoStrings.KeySdc,
+				TermInfoStrings.KeyShelp,
+				TermInfoStrings.KeyShome,
+				TermInfoStrings.KeySleft,
+				TermInfoStrings.KeySprint,
+				TermInfoStrings.KeySright,
+				TermInfoStrings.KeySundo,
+				TermInfoStrings.KeyF11,
+				TermInfoStrings.KeyF12,
+				TermInfoStrings.KeyF13,
+				TermInfoStrings.KeyF14,
+				TermInfoStrings.KeyF15,
+				TermInfoStrings.KeyF16,
+				TermInfoStrings.KeyF17,
+				TermInfoStrings.KeyF18,
+				TermInfoStrings.KeyF19,
+				TermInfoStrings.KeyF20,
+				TermInfoStrings.KeyF21,
+				TermInfoStrings.KeyF22,
+				TermInfoStrings.KeyF23,
+				TermInfoStrings.KeyF24,
+
+				// These were missing
+				TermInfoStrings.KeyDc,
+				TermInfoStrings.KeyIc
+			};
+			
 			foreach (TermInfoStrings tis in UsedKeys)
 				AddStringMapping (tis);
 			

+ 1 - 0
mcs/class/corlib/corlib.dll.sources

@@ -143,6 +143,7 @@ System/DllNotFoundException.cs
 System/DomainManagerInitializationFlags.cs
 System/Double.cs
 System/DuplicateWaitObjectException.cs
+System/EmptyArray.cs
 System/EntryPointNotFoundException.cs
 System/Enum.cs
 System/Environment.cs