Author: nestor
Date: 2007-08-31 10:36:09 -0400 (Fri, 31 Aug 2007)
New Revision: 85132

Modified:
   
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/AvoidUnusedParametersRule.cs
   trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/ChangeLog
Log:
Added two improvements to the existing code.

        * AvoidUnusedParametersRule.cs: Following the Jb Evain comments, I used
        a guard pattern for the method.HasBody in the
        ContainsReferenceDelegateInstructionFor method.  I also
        avoid 2 cast instructions in IsReferencedByDelegateMethod.



Modified: 
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/AvoidUnusedParametersRule.cs
===================================================================
--- 
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/AvoidUnusedParametersRule.cs
  2007-08-31 14:28:52 UTC (rev 85131)
+++ 
trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/AvoidUnusedParametersRule.cs
  2007-08-31 14:36:09 UTC (rev 85132)
@@ -70,25 +70,25 @@
 
                private bool ContainsReferenceDelegateInstructionFor 
(MethodDefinition method, MethodDefinition delegateMethod) 
                {
-                       if (method.HasBody) {
-                               foreach (Instruction instruction in 
method.Body.Instructions) {
-                                       if (instruction.OpCode.Code == 
Code.Ldftn) 
-                                               return 
instruction.Operand.Equals (delegateMethod);
-                               }
+                       if (!method.HasBody) 
+                               return false;
+                       foreach (Instruction instruction in 
method.Body.Instructions) {
+                               if (instruction.OpCode.Code == Code.Ldftn) 
+                                       return instruction.Operand.Equals 
(delegateMethod);
                        }
                        return false;
                }
                
                private bool IsReferencedByDelegate (MethodDefinition 
delegateMethod) 
                {
-                       if (delegateMethod.DeclaringType is TypeDefinition) {
-                               TypeDefinition type = (TypeDefinition) 
delegateMethod.DeclaringType;    
-                               foreach (MethodDefinition method in 
type.Methods) {
+                       TypeDefinition declaringType = 
delegateMethod.DeclaringType as TypeDefinition;
+                       if (declaringType != null) {
+                               foreach (MethodDefinition method in 
declaringType.Methods) {
                                        if 
(ContainsReferenceDelegateInstructionFor (method, delegateMethod)) 
                                                return true;
                                }
 
-                               foreach (MethodDefinition method in 
type.Constructors) {
+                               foreach (MethodDefinition method in 
declaringType.Constructors) {
                                        if 
(ContainsReferenceDelegateInstructionFor (method, delegateMethod))
                                                return true;
                                }

Modified: trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/ChangeLog
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/ChangeLog     
2007-08-31 14:28:52 UTC (rev 85131)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Performance/ChangeLog     
2007-08-31 14:36:09 UTC (rev 85132)
@@ -1,5 +1,12 @@
 2007-09-31  Nestor Salceda  <[EMAIL PROTECTED]>
+       
+       * AvoidUnusedParametersRule.cs: Following the Jb Evain comments, I used
+       a guard pattern for the method.HasBody in the
+       ContainsReferenceDelegateInstructionFor method.  I also avoid 2 cast
+       instructions in IsReferencedByDelegateMethod.
 
+2007-09-31  Nestor Salceda  <[EMAIL PROTECTED]>
+
        * Gendarme.Rules.Performance.xml.in: Added the rule information in the
        xml file.
        

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to