Polishing

(cherry picked from commit 45fc449)
This commit is contained in:
Juergen Hoeller 2016-10-31 19:24:45 +01:00
parent 653f35a3d8
commit ade139f2d0
3 changed files with 48 additions and 47 deletions

View File

@ -58,8 +58,8 @@ public class OpEQ extends Operator {
String leftDesc = left.exitTypeDescriptor; String leftDesc = left.exitTypeDescriptor;
String rightDesc = right.exitTypeDescriptor; String rightDesc = right.exitTypeDescriptor;
DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(leftDesc, rightDesc, DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(
this.leftActualDescriptor, this.rightActualDescriptor); leftDesc, rightDesc, this.leftActualDescriptor, this.rightActualDescriptor);
return (!dc.areNumbers || dc.areCompatible); return (!dc.areNumbers || dc.areCompatible);
} }
@ -73,17 +73,15 @@ public class OpEQ extends Operator {
boolean leftPrim = CodeFlow.isPrimitive(leftDesc); boolean leftPrim = CodeFlow.isPrimitive(leftDesc);
boolean rightPrim = CodeFlow.isPrimitive(rightDesc); boolean rightPrim = CodeFlow.isPrimitive(rightDesc);
DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(leftDesc, rightDesc, DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(
this.leftActualDescriptor, this.rightActualDescriptor); leftDesc, rightDesc, this.leftActualDescriptor, this.rightActualDescriptor);
if (dc.areNumbers && dc.areCompatible) { if (dc.areNumbers && dc.areCompatible) {
char targetType = dc.compatibleType; char targetType = dc.compatibleType;
getLeftOperand().generateCode(mv, cf); getLeftOperand().generateCode(mv, cf);
if (!leftPrim) { if (!leftPrim) {
CodeFlow.insertUnboxInsns(mv, targetType, leftDesc); CodeFlow.insertUnboxInsns(mv, targetType, leftDesc);
} }
cf.enterCompilationScope(); cf.enterCompilationScope();
getRightOperand().generateCode(mv, cf); getRightOperand().generateCode(mv, cf);
cf.exitCompilationScope(); cf.exitCompilationScope();
@ -120,7 +118,7 @@ public class OpEQ extends Operator {
CodeFlow.insertBoxIfNecessary(mv, rightDesc.charAt(0)); CodeFlow.insertBoxIfNecessary(mv, rightDesc.charAt(0));
} }
Label leftNotNull = new Label(); Label leftNotNull = new Label();
mv.visitInsn(DUP_X1); // Dup right on the top of the stack mv.visitInsn(DUP_X1); // dup right on the top of the stack
mv.visitJumpInsn(IFNONNULL, leftNotNull); mv.visitJumpInsn(IFNONNULL, leftNotNull);
// Right is null! // Right is null!
mv.visitInsn(SWAP); mv.visitInsn(SWAP);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -36,12 +36,13 @@ public class OpNE extends Operator {
this.exitTypeDescriptor = "Z"; this.exitTypeDescriptor = "Z";
} }
@Override @Override
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
Object left = getLeftOperand().getValueInternal(state).getValue(); Object left = getLeftOperand().getValueInternal(state).getValue();
Object right = getRightOperand().getValueInternal(state).getValue(); Object right = getRightOperand().getValueInternal(state).getValue();
leftActualDescriptor = CodeFlow.toDescriptorFromObject(left); this.leftActualDescriptor = CodeFlow.toDescriptorFromObject(left);
rightActualDescriptor = CodeFlow.toDescriptorFromObject(right); this.rightActualDescriptor = CodeFlow.toDescriptorFromObject(right);
return BooleanTypedValue.forValue(!equalityCheck(state, left, right)); return BooleanTypedValue.forValue(!equalityCheck(state, left, right));
} }
@ -57,7 +58,8 @@ public class OpNE extends Operator {
String leftDesc = left.exitTypeDescriptor; String leftDesc = left.exitTypeDescriptor;
String rightDesc = right.exitTypeDescriptor; String rightDesc = right.exitTypeDescriptor;
DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(leftDesc, rightDesc, leftActualDescriptor, rightActualDescriptor); DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(
leftDesc, rightDesc, this.leftActualDescriptor, this.rightActualDescriptor);
return (!dc.areNumbers || dc.areCompatible); return (!dc.areNumbers || dc.areCompatible);
} }
@ -70,16 +72,15 @@ public class OpNE extends Operator {
boolean leftPrim = CodeFlow.isPrimitive(leftDesc); boolean leftPrim = CodeFlow.isPrimitive(leftDesc);
boolean rightPrim = CodeFlow.isPrimitive(rightDesc); boolean rightPrim = CodeFlow.isPrimitive(rightDesc);
DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(leftDesc, rightDesc, leftActualDescriptor, rightActualDescriptor); DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(
leftDesc, rightDesc, this.leftActualDescriptor, this.rightActualDescriptor);
if (dc.areNumbers && dc.areCompatible) { if (dc.areNumbers && dc.areCompatible) {
char targetType = dc.compatibleType; char targetType = dc.compatibleType;
getLeftOperand().generateCode(mv, cf); getLeftOperand().generateCode(mv, cf);
if (!leftPrim) { if (!leftPrim) {
CodeFlow.insertUnboxInsns(mv, targetType, leftDesc); CodeFlow.insertUnboxInsns(mv, targetType, leftDesc);
} }
cf.enterCompilationScope(); cf.enterCompilationScope();
getRightOperand().generateCode(mv, cf); getRightOperand().generateCode(mv, cf);
cf.exitCompilationScope(); cf.exitCompilationScope();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -84,6 +84,7 @@ public abstract class Operator extends SpelNodeImpl {
return sb.toString(); return sb.toString();
} }
protected boolean isCompilableOperatorUsingNumerics() { protected boolean isCompilableOperatorUsingNumerics() {
SpelNodeImpl left = getLeftOperand(); SpelNodeImpl left = getLeftOperand();
SpelNodeImpl right= getRightOperand(); SpelNodeImpl right= getRightOperand();
@ -94,8 +95,8 @@ public abstract class Operator extends SpelNodeImpl {
// Supported operand types for equals (at the moment) // Supported operand types for equals (at the moment)
String leftDesc = left.exitTypeDescriptor; String leftDesc = left.exitTypeDescriptor;
String rightDesc = right.exitTypeDescriptor; String rightDesc = right.exitTypeDescriptor;
DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(leftDesc, rightDesc, DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(
this.leftActualDescriptor, this.rightActualDescriptor); leftDesc, rightDesc, this.leftActualDescriptor, this.rightActualDescriptor);
return (dc.areNumbers && dc.areCompatible); return (dc.areNumbers && dc.areCompatible);
} }
@ -109,8 +110,8 @@ public abstract class Operator extends SpelNodeImpl {
boolean unboxLeft = !CodeFlow.isPrimitive(leftDesc); boolean unboxLeft = !CodeFlow.isPrimitive(leftDesc);
boolean unboxRight = !CodeFlow.isPrimitive(rightDesc); boolean unboxRight = !CodeFlow.isPrimitive(rightDesc);
DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(leftDesc, rightDesc, DescriptorComparison dc = DescriptorComparison.checkNumericCompatibility(
this.leftActualDescriptor, this.rightActualDescriptor); leftDesc, rightDesc, this.leftActualDescriptor, this.rightActualDescriptor);
char targetType = dc.compatibleType; // CodeFlow.toPrimitiveTargetDesc(leftDesc); char targetType = dc.compatibleType; // CodeFlow.toPrimitiveTargetDesc(leftDesc);
getLeftOperand().generateCode(mv, cf); getLeftOperand().generateCode(mv, cf);
@ -215,8 +216,8 @@ public abstract class Operator extends SpelNodeImpl {
/** /**
* A descriptor comparison encapsulates the result of comparing descriptor for two operands and * A descriptor comparison encapsulates the result of comparing descriptor
* describes at what level they are compatible. * for two operands and describes at what level they are compatible.
*/ */
protected static class DescriptorComparison { protected static class DescriptorComparison {
@ -237,12 +238,13 @@ public abstract class Operator extends SpelNodeImpl {
} }
/** /**
* Returns an object that indicates whether the input descriptors are compatible. A declared descriptor * Return an object that indicates whether the input descriptors are compatible.
* is what could statically be determined (e.g. from looking at the return value of a property accessor * <p>A declared descriptor is what could statically be determined (e.g. from looking
* method) whilst an actual descriptor is the type of an actual object that was returned, which may differ. * at the return value of a property accessor method) whilst an actual descriptor
* For generic types with unbound type variables the declared descriptor discovered may be 'Object' but * is the type of an actual object that was returned, which may differ.
* from the actual descriptor it is possible to observe that the objects are really numeric values (e.g. * <p>For generic types with unbound type variables, the declared descriptor
* ints). * discovered may be 'Object' but from the actual descriptor it is possible to
* observe that the objects are really numeric values (e.g. ints).
* @param leftDeclaredDescriptor the statically determinable left descriptor * @param leftDeclaredDescriptor the statically determinable left descriptor
* @param rightDeclaredDescriptor the statically determinable right descriptor * @param rightDeclaredDescriptor the statically determinable right descriptor
* @param leftActualDescriptor the dynamic/runtime left object descriptor * @param leftActualDescriptor the dynamic/runtime left object descriptor