aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2019-03-25 20:20:16 +0100
committerReinier Zwitserloot <r.zwitserloot@projectlombok.org>2019-03-25 20:20:22 +0100
commitf8857fdffec01b15a67ca6aad60a1f614fa278e2 (patch)
tree812d46176d8325fb2b1d4a5bb1798470ffd1c5c6
parentcddd9d96ca7afb965c1b4971006360aaac65e8dd (diff)
downloadlombok-f8857fdffec01b15a67ca6aad60a1f614fa278e2.tar.gz
lombok-f8857fdffec01b15a67ca6aad60a1f614fa278e2.tar.bz2
lombok-f8857fdffec01b15a67ca6aad60a1f614fa278e2.zip
[performance] improve typeMatches lookup. Especially in light of the built-in copyable annotations lists growing, this should help performance.
-rwxr-xr-xsrc/core/lombok/core/AST.java11
-rw-r--r--src/core/lombok/core/LombokNode.java9
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java16
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java11
4 files changed, 34 insertions, 13 deletions
diff --git a/src/core/lombok/core/AST.java b/src/core/lombok/core/AST.java
index 78761f46..9f3a471f 100755
--- a/src/core/lombok/core/AST.java
+++ b/src/core/lombok/core/AST.java
@@ -60,6 +60,7 @@ public abstract class AST<A extends AST<A, L, N>, L extends LombokNode<A, L, N>,
private final String fileName;
private final String packageDeclaration;
private final ImportList imports;
+ private TypeResolver importsAsResolver;
Map<N, N> identityDetector = new IdentityHashMap<N, N>();
private Map<N, L> nodeMap = new IdentityHashMap<N, L>();
private boolean changed = false;
@@ -112,14 +113,20 @@ public abstract class AST<A extends AST<A, L, N>, L extends LombokNode<A, L, N>,
/**
* Return the contents of each non-static import statement on this AST's top (Compilation Unit) node.
- *
- * Example: "java.util.IOException".
*/
public final ImportList getImportList() {
return imports;
}
/**
+ * Return the contents of each non-static import statement on this AST's top (Compilation Unit) node, packed into a (cached) TypeResolver.
+ */
+ public final TypeResolver getImportListAsTypeResolver() {
+ if (importsAsResolver != null) return importsAsResolver;
+ return importsAsResolver = new TypeResolver(getImportList());
+ }
+
+ /**
* Puts the given node in the map so that javac/Eclipse's own internal AST object can be translated to
* an AST.Node object. Also registers the object as visited to avoid endless loops.
*/
diff --git a/src/core/lombok/core/LombokNode.java b/src/core/lombok/core/LombokNode.java
index ae8fd325..843a78f0 100644
--- a/src/core/lombok/core/LombokNode.java
+++ b/src/core/lombok/core/LombokNode.java
@@ -97,6 +97,15 @@ public abstract class LombokNode<A extends AST<A, L, N>, L extends LombokNode<A,
}
/**
+ * Convenient shortcut to the owning ast object's {@code getImportListAsTypeResolver} method.
+ *
+ * @see AST#getImportListAsTypeResolver()
+ */
+ public TypeResolver getImportListAsTypeResolver() {
+ return getAst().getImportListAsTypeResolver();
+ }
+
+ /**
* See {@link #isStructurallySignificant}.
*/
protected abstract boolean calculateIsStructurallySignificant(N parent);
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index 9439caf3..78b11873 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -221,14 +221,14 @@ public class EclipseHandlerUtil {
* @param typeRef A type reference to check.
*/
public static boolean typeMatches(String type, EclipseNode node, TypeReference typeRef) {
- if (typeRef == null || typeRef.getTypeName() == null || typeRef.getTypeName().length == 0) return false;
- String lastPartA = new String(typeRef.getTypeName()[typeRef.getTypeName().length -1]);
- int lastIndex = type.lastIndexOf('.');
- String lastPartB = lastIndex == -1 ? type : type.substring(lastIndex + 1);
- if (!lastPartA.equals(lastPartB)) return false;
- String typeName = toQualifiedName(typeRef.getTypeName());
-
- TypeResolver resolver = new TypeResolver(node.getImportList());
+ char[][] tn = typeRef == null ? null : typeRef.getTypeName();
+ if (tn == null || tn.length == 0) return false;
+ char[] lastPartA = tn[tn.length - 1];
+ int lastIndex = type.lastIndexOf('.') + 1;
+ if (lastPartA.length != type.length() - lastIndex) return false;
+ for (int i = 0; i < lastPartA.length; i++) if (lastPartA[i] != type.charAt(i + lastIndex)) return false;
+ String typeName = toQualifiedName(tn);
+ TypeResolver resolver = node.getImportListAsTypeResolver();
return resolver.typeMatches(node, type, typeName);
}
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
index f08098d2..095d1c7a 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -298,9 +298,14 @@ public class JavacHandlerUtil {
* @param typeNode A type reference to check.
*/
public static boolean typeMatches(String type, JavacNode node, JCTree typeNode) {
- String typeName = typeNode.toString();
-
- TypeResolver resolver = new TypeResolver(node.getImportList());
+ String typeName = typeNode == null ? null : typeNode.toString();
+ if (typeName == null || typeName.length() == 0) return false;
+ int lastIndexA = typeName.lastIndexOf('.') + 1;
+ int lastIndexB = type.lastIndexOf('.') + 1;
+ int len = typeName.length() - lastIndexA;
+ if (len != type.length() - lastIndexB) return false;
+ for (int i = 0; i < len; i++) if (typeName.charAt(i + lastIndexA) != type.charAt(i + lastIndexB)) return false;
+ TypeResolver resolver = node.getImportListAsTypeResolver();
return resolver.typeMatches(node, type, typeName);
}