瀏覽代碼

2010-04-02 Marek Safar <[email protected]>

	* MethodBase.cs: Made GetParameterCount abstract and implement
	where missing to avoid redundant allocations.


svn path=/trunk/mcs/; revision=154721
Marek Safar 15 年之前
父節點
當前提交
de9fcae634

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

@@ -256,6 +256,11 @@ namespace System.Reflection.Emit {
 			}
 			return retval;
 		}
+		
+		internal override int GetParameterCount ()
+		{
+			return parameters == null ? 0 : parameters.Length;
+		}		
 
 		/*
 		public override object Invoke (object obj, object[] parameters) {

+ 6 - 0
mcs/class/corlib/System.Reflection.Emit/MonoArrayMethod.cs

@@ -80,6 +80,12 @@ namespace System.Reflection {
 		public override ParameterInfo[] GetParameters() {
 			return new ParameterInfo [0];
 		}
+		
+		[MonoTODO("Not implemented.  Always returns 0")]
+		internal override int GetParameterCount ()
+		{
+			return 0;
+		}		
 
 		[MonoTODO("Not implemented")]
 		public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {

+ 5 - 0
mcs/class/corlib/System.Reflection/ChangeLog

@@ -1,3 +1,8 @@
+2010-04-02  Marek Safar  <[email protected]>
+
+	* MethodBase.cs: Made GetParameterCount abstract and implement
+	where missing to avoid redundant allocations.
+
 2010-04-01 Rodrigo Kumpera  <[email protected]>
 
 	* Module.cs (GetMethod): Check for null 'types' argument.

+ 1 - 15
mcs/class/corlib/System.Reflection/MethodBase.cs

@@ -85,21 +85,7 @@ namespace System.Reflection {
 		// This is a quick version for our own use. We should override
 		// it where possible so that it does not allocate an array.
 		//
-		internal virtual int GetParameterCount ()
-		{
-			ParameterInfo [] pi = GetParameters ();
-			if (pi == null)
-				return 0;
-			
-			return pi.Length;
-		}
-
-#if ONLY_1_1
-		public new Type GetType ()
-		{
-			return base.GetType ();
-		}
-#endif
+		internal abstract int GetParameterCount ();
 
 		[DebuggerHidden]
 		[DebuggerStepThrough]		

+ 12 - 0
mcs/class/corlib/System.Reflection/MonoMethod.cs

@@ -168,6 +168,12 @@ namespace System.Reflection {
 			src.CopyTo (res, 0);
 			return res;
 		}
+		
+		internal override int GetParameterCount ()
+		{
+			var pi = MonoMethodInfo.GetParametersInfo (mhandle, this);
+			return pi == null ? 0 : pi.Length;
+		}
 
 		/*
 		 * InternalInvoke() receives the parameters correctly converted by the 
@@ -462,6 +468,12 @@ namespace System.Reflection {
 			return MonoMethodInfo.GetParametersInfo (mhandle, this);
 		}
 
+		internal override int GetParameterCount ()
+		{
+			var pi = MonoMethodInfo.GetParametersInfo (mhandle, this);
+			return pi == null ? 0 : pi.Length;
+		}
+
 		/*
 		 * InternalInvoke() receives the parameters corretcly converted by the binder
 		 * to match the types of the method signature.