ソースを参照

2009-03-06 Rodrigo Kumpera <[email protected]>

	* MonoType.cs (MonoTypeInfo): Add default_ctor field.

	* MonoType.cs: Add GetDefaultConstructor that caches using
	type_info.default_ctor.

	* MonoType.cs (FullName): Protects against type_info been replaced
	under the hood.

	* Activator.cs (CreateInstance): If the type is a MonoType resolve the
	default constructor using the new method from MonoType.

	Improves Activator::CreateInstance performance by at least 30%, reduces object churn
	and domain lock contention.

svn path=/trunk/mcs/; revision=128795
Rodrigo Kumpera 17 年 前
コミット
9dfd018a50

+ 13 - 5
mcs/class/corlib/System/Activator.cs

@@ -306,11 +306,19 @@ namespace System
 #endif
 			CheckAbstractType (type);
 
-			BindingFlags flags = BindingFlags.Public | BindingFlags.Instance;
-			if (nonPublic)
-				flags |= BindingFlags.NonPublic;
-
-			ConstructorInfo ctor = type.GetConstructor (flags, null, CallingConventions.Any, Type.EmptyTypes, null);
+			ConstructorInfo ctor;
+			MonoType monoType = type as MonoType;
+
+			if (monoType != null) {
+				ctor = monoType.GetDefaultConstructor ();
+				if (!nonPublic && ctor != null && !ctor.IsPublic)
+					ctor = null;
+			} else {
+				BindingFlags flags = BindingFlags.Public | BindingFlags.Instance;
+				if (nonPublic)
+					flags |= BindingFlags.NonPublic;
+				ctor = type.GetConstructor (flags, null, CallingConventions.Any, Type.EmptyTypes, null);
+			}
 
 			if (ctor == null) {
 				if (type.IsValueType)

+ 16 - 0
mcs/class/corlib/System/ChangeLog

@@ -1,3 +1,19 @@
+2009-03-06  Rodrigo Kumpera  <[email protected]>
+
+	* MonoType.cs (MonoTypeInfo): Add default_ctor field.
+
+	* MonoType.cs: Add GetDefaultConstructor that caches using
+	type_info.default_ctor.
+
+	* MonoType.cs (FullName): Protects against type_info been replaced
+	under the hood.
+
+	* Activator.cs (CreateInstance): If the type is a MonoType resolve the
+	default constructor using the new method from MonoType.
+
+	Improves Activator::CreateInstance performance by at least 30%, reduces object churn
+	and domain lock contention.
+
 2009-03-03  Rodrigo Kumpera  <[email protected]>
 
 	* Guid.cs (BaseToString): Reduce allocations.

+ 19 - 3
mcs/class/corlib/System/MonoType.cs

@@ -41,6 +41,7 @@ namespace System
 	// Contains information about the type which is expensive to compute
 	internal class MonoTypeInfo {
 		public string full_name;
+		public ConstructorInfo default_ctor;
 	}
 		
 	[Serializable]
@@ -62,7 +63,21 @@ namespace System
 
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
 		private static extern TypeAttributes get_attributes (Type type);
+
+		internal ConstructorInfo GetDefaultConstructor () {
+			ConstructorInfo ctor = null;
+			
+			if (type_info == null)
+				type_info = new MonoTypeInfo ();
+			if ((ctor = type_info.default_ctor) == null) {
+				BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic;
 	
+				 ctor = type_info.default_ctor = GetConstructor (flags,  null, CallingConventions.Any, Type.EmptyTypes, null);
+			}
+
+			return ctor;
+		}
+
 		protected override TypeAttributes GetAttributeFlagsImpl ()
 		{
 			return get_attributes (this);
@@ -529,13 +544,14 @@ namespace System
 
 		public override string FullName {
 			get {
+				string fullName;
 				// This doesn't need locking
 				if (type_info == null)
 					type_info = new MonoTypeInfo ();
-				if (type_info.full_name == null)
-					type_info.full_name = getFullName (true, false);
+				if ((fullName = type_info.full_name) == null)
+					fullName = type_info.full_name = getFullName (true, false);
 
-				return type_info.full_name;
+				return fullName;
 			}
 		}