Author: marek
Date: 2006-12-20 07:04:21 -0500 (Wed, 20 Dec 2006)
New Revision: 69806
Modified:
trunk/mcs/mcs/ChangeLog
trunk/mcs/mcs/expression.cs
Log:
2006-12-20 Marek Safar <[EMAIL PROTECTED]>
A fix for bug #80288
* expression.cs (ResolveOperator): Consider user defined conversion for
logical and operator too.
(EmitBranchable): Optimization for logical and when full constant
folding
could not be applied but one operand is constant.
Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog 2006-12-20 11:56:11 UTC (rev 69805)
+++ trunk/mcs/mcs/ChangeLog 2006-12-20 12:04:21 UTC (rev 69806)
@@ -1,3 +1,11 @@
+2006-12-20 Marek Safar <[EMAIL PROTECTED]>
+
+ A fix for bug #80288
+ * expression.cs (ResolveOperator): Consider user defined conversion for
+ logical and operator too.
+ (EmitBranchable): Optimization for logical and when full constant
folding
+ could not be applied but one operand is constant.
+
2006-12-19 Marek Safar <[EMAIL PROTECTED]>
* class.cs (GetClassBases): Write 5 times every day, will never use
Modified: trunk/mcs/mcs/expression.cs
===================================================================
--- trunk/mcs/mcs/expression.cs 2006-12-20 11:56:11 UTC (rev 69805)
+++ trunk/mcs/mcs/expression.cs 2006-12-20 12:04:21 UTC (rev 69806)
@@ -2090,9 +2090,16 @@
return this;
}
- if (l != r) {
- Error_OperatorCannotBeApplied ();
- return null;
+ left_operators = l == TypeManager.bool_type ?
+ left : Convert.ImplicitUserConversion
(ec, left, TypeManager.bool_type, loc);
+ right_operators = r == TypeManager.bool_type ?
+ right : Convert.ImplicitUserConversion
(ec, right, TypeManager.bool_type, loc);
+
+ if (left_operators != null && right_operators
!= null) {
+ left = left_operators;
+ right = right_operators;
+ type = TypeManager.bool_type;
+ return this;
}
Expression e = new ConditionalLogicalOperator (
@@ -2485,8 +2492,15 @@
right.EmitBranchable (ec, target, true);
ig.MarkLabel (tests_end);
} else {
- left.EmitBranchable (ec, target, false);
- right.EmitBranchable (ec, target,
false);
+ //
+ // This optimizes code like this
+ // if (true && i > 4)
+ //
+ if (!(left is Constant))
+ left.EmitBranchable (ec,
target, false);
+
+ if (!(right is Constant))
+ right.EmitBranchable (ec,
target, false);
}
return;
@@ -3033,7 +3047,7 @@
left_temp = new LocalTemporary (type);
- ArrayList arguments = new ArrayList ();
+ ArrayList arguments = new ArrayList (2);
arguments.Add (new Argument (left_temp,
Argument.AType.Expression));
arguments.Add (new Argument (right,
Argument.AType.Expression));
method = Invocation.OverloadResolve (
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches