summaryrefslogtreecommitdiffstats
path: root/weaver/src
diff options
context:
space:
mode:
authoraclement <aclement>2006-02-13 10:51:24 +0000
committeraclement <aclement>2006-02-13 10:51:24 +0000
commit67ef5e265751297e19bed06372330dfc2124cd73 (patch)
treedb6916d65a3a05ab9ac4ced221fd3eff84ff4ce2 /weaver/src
parent0b39aa5dd0218561f11258ac272112ada447065e (diff)
downloadaspectj-67ef5e265751297e19bed06372330dfc2124cd73.tar.gz
aspectj-67ef5e265751297e19bed06372330dfc2124cd73.zip
lessen the cost of hashcode and equals
Diffstat (limited to 'weaver/src')
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/NamePattern.java13
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java25
2 files changed, 24 insertions, 14 deletions
diff --git a/weaver/src/org/aspectj/weaver/patterns/NamePattern.java b/weaver/src/org/aspectj/weaver/patterns/NamePattern.java
index 45f4b154a..abcceb841 100644
--- a/weaver/src/org/aspectj/weaver/patterns/NamePattern.java
+++ b/weaver/src/org/aspectj/weaver/patterns/NamePattern.java
@@ -21,6 +21,7 @@ import org.aspectj.weaver.VersionedDataInputStream;
public class NamePattern extends PatternNode {
char[] pattern;
int starCount = 0;
+ private int hashcode = -1;
public static final NamePattern ELLIPSIS = new NamePattern("");
public static final NamePattern ANY = new NamePattern("*");
@@ -35,6 +36,7 @@ public class NamePattern extends PatternNode {
for (int i=0, len=pattern.length; i<len; i++) {
if (pattern[i] == '*') starCount++;
}
+ hashcode = new String(pattern).hashCode();
}
public boolean matches(char[] a2) {
@@ -122,13 +124,18 @@ public class NamePattern extends PatternNode {
public boolean equals(Object other) {
if (other instanceof NamePattern) {
NamePattern otherPat = (NamePattern)other;
- return otherPat.starCount == this.starCount &&
- new String(otherPat.pattern).equals(new String(this.pattern));
+ if (otherPat.starCount!=this.starCount) return false;
+ if (otherPat.pattern.length!=this.pattern.length) return false;
+ for (int i = 0; i < this.pattern.length; i++) {
+ if (this.pattern[i]!=otherPat.pattern[i]) return false;
+ }
+ return true;
}
return false;
}
+
public int hashCode() {
- return new String(pattern).hashCode();
+ return hashcode;
}
diff --git a/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java b/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java
index 1e9369666..94953c295 100644
--- a/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java
+++ b/weaver/src/org/aspectj/weaver/patterns/SignaturePattern.java
@@ -55,6 +55,7 @@ public class SignaturePattern extends PatternNode {
private TypePatternList parameterTypes;
private ThrowsPattern throwsPattern;
private AnnotationTypePattern annotationPattern;
+ private transient int hashcode = -1;
public SignaturePattern(Member.Kind kind, ModifiersPattern modifiers,
TypePattern returnType, TypePattern declaringType,
@@ -96,7 +97,7 @@ public class SignaturePattern extends PatternNode {
annotationPattern = annotationPattern.resolveBindings(scope,bindings,false);
checkForIncorrectTargetKind(annotationPattern,scope,true);
}
-
+ hashcode =-1;
return this;
}
@@ -629,16 +630,18 @@ public class SignaturePattern extends PatternNode {
&& o.annotationPattern.equals(this.annotationPattern);
}
public int hashCode() {
- int result = 17;
- result = 37*result + kind.hashCode();
- result = 37*result + modifiers.hashCode();
- result = 37*result + returnType.hashCode();
- result = 37*result + declaringType.hashCode();
- result = 37*result + name.hashCode();
- result = 37*result + parameterTypes.hashCode();
- result = 37*result + throwsPattern.hashCode();
- result = 37*result + annotationPattern.hashCode();
- return result;
+ if (hashcode==-1) {
+ hashcode = 17;
+ hashcode = 37*hashcode + kind.hashCode();
+ hashcode = 37*hashcode + modifiers.hashCode();
+ hashcode = 37*hashcode + returnType.hashCode();
+ hashcode = 37*hashcode + declaringType.hashCode();
+ hashcode = 37*hashcode + name.hashCode();
+ hashcode = 37*hashcode + parameterTypes.hashCode();
+ hashcode = 37*hashcode + throwsPattern.hashCode();
+ hashcode = 37*hashcode + annotationPattern.hashCode();
+ }
+ return hashcode;
}
public void write(DataOutputStream s) throws IOException {