From 17229916f59b8eb79af2f2e930cdd529520f5341 Mon Sep 17 00:00:00 2001 From: aclement Date: Wed, 25 Feb 2009 20:11:15 +0000 Subject: [PATCH] 266165: if(enabled) where enabled is constant boolean is optimized --- .../src/org/aspectj/weaver/Advice.java | 16 ++++---- .../aspectj/weaver/patterns/IfPointcut.java | 37 ++++++++++++++++++- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/Advice.java b/org.aspectj.matcher/src/org/aspectj/weaver/Advice.java index 9d79ff7e3..08426a197 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/Advice.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/Advice.java @@ -294,7 +294,6 @@ public abstract class Advice extends ShadowMunger { return result; } - /** * Return the type of the 'extra argument'. For either after returning or after throwing advice, the extra argument will be the * returned value or the thrown exception respectively. With annotation style the user may declare the parameters in any order, @@ -459,12 +458,15 @@ public abstract class Advice extends ShadowMunger { // ---- fields - public static final int ExtraArgument = 1; - public static final int ThisJoinPoint = 2; - public static final int ThisJoinPointStaticPart = 4; - public static final int ThisEnclosingJoinPointStaticPart = 8; - public static final int ParameterMask = 0xf; - + public static final int ExtraArgument = 0x01; + public static final int ThisJoinPoint = 0x02; + public static final int ThisJoinPointStaticPart = 0x04; + public static final int ThisEnclosingJoinPointStaticPart = 0x08; + public static final int ParameterMask = 0x0f; + // For an if pointcut, this indicates it is hard wired to access a constant of either true or false + public static final int ConstantReference = 0x10; + // When the above flag is set, this indicates whether it is true or false + public static final int ConstantValue = 0x20; public static final int CanInline = 0x40; // for testing only diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/IfPointcut.java b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/IfPointcut.java index 1e5b3cb43..34b7d51a0 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/IfPointcut.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/IfPointcut.java @@ -82,6 +82,13 @@ public class IfPointcut extends Pointcut { } protected FuzzyBoolean matchInternal(Shadow shadow) { + if ((extraParameterFlags & Advice.ConstantReference) != 0) { + if ((extraParameterFlags & Advice.ConstantValue) != 0) { + return FuzzyBoolean.YES; + } else { + return FuzzyBoolean.NO; + } + } // ??? this is not maximally efficient return FuzzyBoolean.MAYBE; } @@ -160,8 +167,9 @@ public class IfPointcut extends Pointcut { * At each shadow that matched, the residue can be different. */ protected Test findResidueInternal(Shadow shadow, ExposedState state) { - if (findingResidue) + if (findingResidue) { return Literal.TRUE; + } findingResidue = true; try { @@ -174,6 +182,22 @@ public class IfPointcut extends Pointcut { // code style if (extraParameterFlags >= 0) { + if ((extraParameterFlags & Advice.ConstantReference) != 0) { + // it is either always true or always false, no need for test + if ((extraParameterFlags & Advice.ConstantValue) != 0) { + ret = Literal.TRUE; + ifLastMatchedShadowId = shadow.shadowId; + ifLastMatchedShadowResidue = ret; + return ret; + } else { + // Dont think we should be in here as the match cannot have succeeded... + ret = Literal.FALSE; + ifLastMatchedShadowId = shadow.shadowId; + ifLastMatchedShadowResidue = ret; + return ret; + } + } + // If there are no args to sort out, don't bother with the recursive call if (baseArgsCount > 0) { ExposedState myState = new ExposedState(baseArgsCount); @@ -528,4 +552,15 @@ public class IfPointcut extends Pointcut { } } + /** + * Called when it is determined that the pointcut refers to a constant value of TRUE or FALSE - enabling exact matching and no + * unnecessary calls to the method representing the if body. + */ + public void setAlways(boolean matches) { + extraParameterFlags |= Advice.ConstantReference; + if (matches) { + extraParameterFlags |= Advice.ConstantValue; + } + } + } -- 2.39.5