| Index: lib/compiler/implementation/ssa/codegen.dart
|
| diff --git a/lib/compiler/implementation/ssa/codegen.dart b/lib/compiler/implementation/ssa/codegen.dart
|
| index 3b798e90166f124ae332d6251f5e0601ceea7300..2ad7d60177420fa375dcc6a9a87284d486efcba4 100644
|
| --- a/lib/compiler/implementation/ssa/codegen.dart
|
| +++ b/lib/compiler/implementation/ssa/codegen.dart
|
| @@ -1231,45 +1231,35 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
|
| }
|
|
|
| void emitIdentityComparison(HInstruction left, HInstruction right) {
|
| - HType leftType = left.propagatedType;
|
| - HType rightType = right.propagatedType;
|
| - if (leftType.canBeNull() && rightType.canBeNull()) {
|
| - if (left.isConstantNull() || right.isConstantNull() ||
|
| - (leftType.isPrimitive() && leftType == rightType)) {
|
| + String op = singleIdentityComparison(left, right);
|
| + if (op != null) {
|
| + beginExpression(JSPrecedence.EQUALITY_PRECEDENCE);
|
| + use(left, JSPrecedence.EQUALITY_PRECEDENCE);
|
| + buffer.add(' $op ');
|
| + use(right, JSPrecedence.RELATIONAL_PRECEDENCE);
|
| + endExpression(JSPrecedence.EQUALITY_PRECEDENCE);
|
| + } else {
|
| + assert(NullConstant.JsNull == 'null');
|
| + withPrecedence(JSPrecedence.CONDITIONAL_PRECEDENCE, () {
|
| beginExpression(JSPrecedence.EQUALITY_PRECEDENCE);
|
| use(left, JSPrecedence.EQUALITY_PRECEDENCE);
|
| - buffer.add(' == ');
|
| - use(right, JSPrecedence.RELATIONAL_PRECEDENCE);
|
| + buffer.add(' == null');
|
| endExpression(JSPrecedence.EQUALITY_PRECEDENCE);
|
| - } else {
|
| - assert(NullConstant.JsNull == 'null');
|
| - withPrecedence(JSPrecedence.CONDITIONAL_PRECEDENCE, () {
|
| + buffer.add(' ? ');
|
| + this.expectedPrecedence = JSPrecedence.ASSIGNMENT_PRECEDENCE;
|
| + withPrecedence(JSPrecedence.LOGICAL_AND_PRECEDENCE, () {
|
| beginExpression(JSPrecedence.EQUALITY_PRECEDENCE);
|
| - use(left, JSPrecedence.EQUALITY_PRECEDENCE);
|
| + use(right, JSPrecedence.EQUALITY_PRECEDENCE);
|
| buffer.add(' == null');
|
| endExpression(JSPrecedence.EQUALITY_PRECEDENCE);
|
| - buffer.add(' ? ');
|
| - this.expectedPrecedence = JSPrecedence.ASSIGNMENT_PRECEDENCE;
|
| - withPrecedence(JSPrecedence.LOGICAL_AND_PRECEDENCE, () {
|
| - beginExpression(JSPrecedence.EQUALITY_PRECEDENCE);
|
| - use(right, JSPrecedence.EQUALITY_PRECEDENCE);
|
| - buffer.add(' == null');
|
| - endExpression(JSPrecedence.EQUALITY_PRECEDENCE);
|
| - buffer.add(" : ");
|
| - beginExpression(JSPrecedence.EQUALITY_PRECEDENCE);
|
| - use(left, JSPrecedence.EQUALITY_PRECEDENCE);
|
| - buffer.add(' === ');
|
| - use(right, JSPrecedence.EQUALITY_PRECEDENCE);
|
| - endExpression(JSPrecedence.EQUALITY_PRECEDENCE);
|
| - });
|
| + buffer.add(" : ");
|
| + beginExpression(JSPrecedence.EQUALITY_PRECEDENCE);
|
| + use(left, JSPrecedence.EQUALITY_PRECEDENCE);
|
| + buffer.add(' === ');
|
| + use(right, JSPrecedence.EQUALITY_PRECEDENCE);
|
| + endExpression(JSPrecedence.EQUALITY_PRECEDENCE);
|
| });
|
| - }
|
| - } else {
|
| - beginExpression(JSPrecedence.EQUALITY_PRECEDENCE);
|
| - use(left, JSPrecedence.EQUALITY_PRECEDENCE);
|
| - buffer.add(' === ');
|
| - use(right, JSPrecedence.RELATIONAL_PRECEDENCE);
|
| - endExpression(JSPrecedence.EQUALITY_PRECEDENCE);
|
| + });
|
| }
|
| }
|
|
|
| @@ -3115,3 +3105,19 @@ class SsaUnoptimizedCodeGenerator extends SsaCodeGenerator {
|
| }
|
| }
|
| }
|
| +
|
| +String singleIdentityComparison(HInstruction left, HInstruction right) {
|
| + // Returns the single identity comparison (== or ===) or null if a more
|
| + // complex expression is required.
|
| + HType leftType = left.propagatedType;
|
| + HType rightType = right.propagatedType;
|
| + if (leftType.canBeNull() && rightType.canBeNull()) {
|
| + if (left.isConstantNull() || right.isConstantNull() ||
|
| + (leftType.isPrimitive() && leftType == rightType)) {
|
| + return '==';
|
| + }
|
| + return null;
|
| + } else {
|
| + return '===';
|
| + }
|
| +}
|
|
|