diff options
author | Andrew Clement <aclement@vmware.com> | 2025-03-25 16:38:34 -0700 |
---|---|---|
committer | Andrew Clement <aclement@vmware.com> | 2025-03-25 16:38:34 -0700 |
commit | fc46e12f52fabad64e91041d37bfb0dc43333eb0 (patch) | |
tree | 40cfefe46823cfda029398fbcb9fd8e72498d7c6 /org.aspectj.matcher/src/main/java | |
parent | b9e22803ad2772a704547aa46f45eeb1cd66c3ef (diff) | |
download | aspectj-master.tar.gz aspectj-master.zip |
Fixes #323: UnresolvedType#getDimensions uses uncompiled regex, resulting in 97% of memory allocated in Pattern.compileHEADmaster
I say 'fixes' but all I did was use a different implementation. I don't have
a testcase that gives the memory problem but the new implementation
doesn't use Pattern so it can't give the same behaviour.
Perhaps Pattern matching is better for some situation I'm unaware of but
my microbenchmarks on this approach seem to suggest it is much faster and
the tests all seem to pass.
Fixes #323
Diffstat (limited to 'org.aspectj.matcher/src/main/java')
-rw-r--r-- | org.aspectj.matcher/src/main/java/org/aspectj/weaver/UnresolvedType.java | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/UnresolvedType.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/UnresolvedType.java index e911ba44f..048f30cae 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/UnresolvedType.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/UnresolvedType.java @@ -17,6 +17,8 @@ package org.aspectj.weaver; import java.io.DataInputStream; import java.io.IOException; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.aspectj.util.GenericSignature; import org.aspectj.util.GenericSignature.ClassSignature; @@ -160,9 +162,13 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { public final boolean isArray() { return signature.length() > 0 && signature.charAt(0) == '['; } - + public final int getDimensions() { - return signature.replaceAll("^(\\[*).*", "$1").length(); + int d = 0; + for (int i=0;i<signature.length() && signature.charAt(i)=='[';i++) { + d++; + } + return d; } /** |