From cffe952902c5b317d246367aefdddee4021ce280 Mon Sep 17 00:00:00 2001 From: aclement Date: Sat, 7 Nov 2009 01:03:51 +0000 Subject: [PATCH] minor optimizations --- .../weaver/JoinPointSignatureIterator.java | 3 +- .../weaver/patterns/DeclareAnnotation.java | 8 ++--- .../weaver/patterns/WildTypePattern.java | 29 ++++++++++++------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/JoinPointSignatureIterator.java b/org.aspectj.matcher/src/org/aspectj/weaver/JoinPointSignatureIterator.java index fbade1212..1597989ed 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/JoinPointSignatureIterator.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/JoinPointSignatureIterator.java @@ -109,7 +109,8 @@ public class JoinPointSignatureIterator implements Iterator return; } - firstDefiningMember = signaturesOfMember.resolve(world); + firstDefiningMember = (signaturesOfMember instanceof ResolvedMember ? + (ResolvedMember) signaturesOfMember: signaturesOfMember.resolve(world)); if (firstDefiningMember == null) { couldBeFurtherAsYetUndiscoveredSignatures = false; diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/DeclareAnnotation.java b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/DeclareAnnotation.java index 94c55c251..3f8a01e69 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/DeclareAnnotation.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/DeclareAnnotation.java @@ -326,8 +326,8 @@ public class DeclareAnnotation extends Declare { if (annotation != null) { return; } - for (Iterator iter = containingAspect.getMethods(false); iter.hasNext();) { - ResolvedMember member = iter.next(); + for (Iterator iter = containingAspect.getMethods(); iter.hasNext();) { + ResolvedMember member = (ResolvedMember) iter.next(); if (member.getName().equals(annotationMethod)) { AnnotationAJ[] annos = member.getAnnotations(); if (annos == null) { @@ -388,8 +388,8 @@ public class DeclareAnnotation extends Declare { */ public ResolvedType getAnnotationType() { if (annotationType == null) { - for (Iterator iter = containingAspect.getMethods(false); iter.hasNext();) { - ResolvedMember member = iter.next(); + for (Iterator iter = containingAspect.getMethods(); iter.hasNext();) { + ResolvedMember member = (ResolvedMember) iter.next(); if (member.getName().equals(annotationMethod)) { ResolvedType[] annoTypes = member.getAnnotationTypes(); if (annoTypes == null) { diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/WildTypePattern.java b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/WildTypePattern.java index 6dac7fff9..3ace8ac1e 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/WildTypePattern.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/WildTypePattern.java @@ -347,9 +347,12 @@ public class WildTypePattern extends TypePattern { } } else { for (int i = 0, len = knownMatches.length; i < len; i++) { - String knownPrefix = knownMatches[i] + "$"; - if (targetTypeName.startsWith(knownPrefix)) { - int pos = lastIndexOfDotOrDollar(knownMatches[i]); + String knownMatch = knownMatches[i]; + // String knownPrefix = knownMatches[i] + "$"; + // if (targetTypeName.startsWith(knownPrefix)) { + if (targetTypeName.startsWith(knownMatch) && targetTypeName.length() > knownMatch.length() + && targetTypeName.charAt(knownMatch.length()) == '$') { + int pos = lastIndexOfDotOrDollar(knownMatch); if (innerMatchesExactly(targetTypeName.substring(pos + 1), isAnonymous, isNested)) { return true; } @@ -374,14 +377,18 @@ public class WildTypePattern extends TypePattern { } private int lastIndexOfDotOrDollar(String string) { - int dot = string.lastIndexOf('.'); - int dollar = string.lastIndexOf('$'); - return Math.max(dot, dollar); + for (int pos = string.length() - 1; pos > -1; pos--) { + char ch = string.charAt(pos); + if (ch == '.' || ch == '$') { + return pos; + } + } + return -1; } private boolean innerMatchesExactly(String s, boolean isAnonymous, boolean convertDollar /* isNested */) { - List ret = new ArrayList(); + List ret = new ArrayList(); int startIndex = 0; while (true) { int breakIndex = s.indexOf('.', startIndex); // what about / @@ -412,7 +419,7 @@ public class WildTypePattern extends TypePattern { return false; } while (patternsIndex < patternsLength) { - if (!namePatterns[patternsIndex++].matches((char[]) ret.get(namesIndex++))) { + if (!namePatterns[patternsIndex++].matches(ret.get(namesIndex++))) { return false; } } @@ -426,7 +433,7 @@ public class WildTypePattern extends TypePattern { if (p == NamePattern.ELLIPSIS) { namesIndex = namesLength - (patternsLength - patternsIndex); } else { - if (!p.matches((char[]) ret.get(namesIndex++))) { + if (!p.matches(ret.get(namesIndex++))) { return false; } } @@ -434,8 +441,8 @@ public class WildTypePattern extends TypePattern { return true; } else { // System.err.print("match(\"" + Arrays.asList(namePatterns) + "\", \"" + Arrays.asList(names) + "\") -> "); - boolean b = outOfStar(namePatterns, (char[][]) ret.toArray(new char[ret.size()][]), 0, 0, patternsLength - - ellipsisCount, namesLength, ellipsisCount); + boolean b = outOfStar(namePatterns, ret.toArray(new char[ret.size()][]), 0, 0, patternsLength - ellipsisCount, + namesLength, ellipsisCount); // System.err.println(b); return b; } -- 2.39.5