Skip to content

Commit fc46e12

Browse files
committed
Fixes #323: UnresolvedType#getDimensions uses uncompiled regex, resulting in 97% of memory allocated in Pattern.compile
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
1 parent b9e2280 commit fc46e12

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

org.aspectj.matcher/src/main/java/org/aspectj/weaver/UnresolvedType.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import java.io.DataInputStream;
1818
import java.io.IOException;
1919
import java.util.Map;
20+
import java.util.regex.Matcher;
21+
import java.util.regex.Pattern;
2022

2123
import org.aspectj.util.GenericSignature;
2224
import org.aspectj.util.GenericSignature.ClassSignature;
@@ -160,9 +162,13 @@ public TypeKind getTypekind() {
160162
public final boolean isArray() {
161163
return signature.length() > 0 && signature.charAt(0) == '[';
162164
}
163-
165+
164166
public final int getDimensions() {
165-
return signature.replaceAll("^(\\[*).*", "$1").length();
167+
int d = 0;
168+
for (int i=0;i<signature.length() && signature.charAt(i)=='[';i++) {
169+
d++;
170+
}
171+
return d;
166172
}
167173

168174
/**

0 commit comments

Comments
 (0)