aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2023-03-21 17:10:34 +0100
committerGitHub <noreply@github.com>2023-03-21 17:10:34 +0100
commitf494c8efeace03501d5251c08dde0f740d4acf24 (patch)
tree0294b515ec5ce8572383be2eb146ec16678046c2 /src/core/lombok
parentf22f6d7e135fc86fb7383b0e8b604d328eaf1725 (diff)
parentf13750c271accf72bcdb69a67795233aa99931e3 (diff)
downloadlombok-f494c8efeace03501d5251c08dde0f740d4acf24.tar.gz
lombok-f494c8efeace03501d5251c08dde0f740d4acf24.tar.bz2
lombok-f494c8efeace03501d5251c08dde0f740d4acf24.zip
Merge pull request #3356 from dreis2211/reduce-allocations-typematch
Reduce allocations from JavacHandlerUtil.typeMatches()
Diffstat (limited to 'src/core/lombok')
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
index 593a1aa8..ac947581 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -313,7 +313,11 @@ public class JavacHandlerUtil {
* @param typeNode A type reference to check.
*/
public static boolean typeMatches(String type, JavacNode node, JCTree typeNode) {
- String typeName = typeNode == null ? null : typeNode.toString();
+ String typeName = getTypeName(typeNode);
+ return typeMatches(type, node, typeName);
+ }
+
+ private static boolean typeMatches(String type, JavacNode node, String typeName) {
if (typeName == null || typeName.length() == 0) return false;
int lastIndexA = typeName.lastIndexOf('.') + 1;
int lastIndexB = Math.max(type.lastIndexOf('.'), type.lastIndexOf('$')) + 1;
@@ -323,7 +327,11 @@ public class JavacHandlerUtil {
TypeResolver resolver = node.getImportListAsTypeResolver();
return resolver.typeMatches(node, type, typeName);
}
-
+
+ private static String getTypeName(JCTree typeNode) {
+ return typeNode == null ? null : typeNode.toString();
+ }
+
/**
* Returns if a field is marked deprecated, either by {@code @Deprecated} or in javadoc
* @param field the field to check
@@ -1665,7 +1673,8 @@ public class JavacHandlerUtil {
for (JavacNode child : node.down()) {
if (child.getKind() == Kind.ANNOTATION) {
JCAnnotation annotation = (JCAnnotation) child.get();
- for (String nn : NONNULL_ANNOTATIONS) if (typeMatches(nn, node, annotation.annotationType)) return true;
+ String annotationTypeName = getTypeName(annotation.annotationType);
+ for (String nn : NONNULL_ANNOTATIONS) if (typeMatches(nn, node, annotationTypeName)) return true;
}
}
@@ -1675,7 +1684,8 @@ public class JavacHandlerUtil {
public static boolean hasNonNullAnnotations(JavacNode node, List<JCAnnotation> anns) {
if (anns == null) return false;
for (JCAnnotation ann : anns) {
- for (String nn : NONNULL_ANNOTATIONS) if (typeMatches(nn, node, ann)) return true;
+ String annotationTypeName = getTypeName(ann.annotationType);
+ for (String nn : NONNULL_ANNOTATIONS) if (typeMatches(nn, node, annotationTypeName)) return true;
}
return false;
@@ -1704,21 +1714,22 @@ public class JavacHandlerUtil {
java.util.List<TypeName> configuredCopyable = node.getAst().readConfiguration(ConfigurationKeys.COPYABLE_ANNOTATIONS);
if (!annoName.isEmpty()) {
- for (TypeName cn : configuredCopyable) if (cn != null && typeMatches(cn.toString(), node, anno.annotationType)) return List.of(anno);
- for (String bn : BASE_COPYABLE_ANNOTATIONS) if (typeMatches(bn, node, anno.annotationType)) return List.of(anno);
+ for (TypeName cn : configuredCopyable) if (cn != null && typeMatches(cn.toString(), node, annoName)) return List.of(anno);
+ for (String bn : BASE_COPYABLE_ANNOTATIONS) if (typeMatches(bn, node, annoName)) return List.of(anno);
}
-
+
ListBuffer<JCAnnotation> result = new ListBuffer<JCAnnotation>();
for (JavacNode child : node.down()) {
if (child.getKind() == Kind.ANNOTATION) {
JCAnnotation annotation = (JCAnnotation) child.get();
+ String annotationTypeName = getTypeName(annotation.annotationType);
boolean match = false;
- for (TypeName cn : configuredCopyable) if (cn != null && typeMatches(cn.toString(), node, annotation.annotationType)) {
+ for (TypeName cn : configuredCopyable) if (cn != null && typeMatches(cn.toString(), node, annotationTypeName)) {
result.append(annotation);
match = true;
break;
}
- if (!match) for (String bn : BASE_COPYABLE_ANNOTATIONS) if (typeMatches(bn, node, annotation.annotationType)) {
+ if (!match) for (String bn : BASE_COPYABLE_ANNOTATIONS) if (typeMatches(bn, node, annotationTypeName)) {
result.append(annotation);
break;
}
@@ -1762,15 +1773,16 @@ public class JavacHandlerUtil {
if (annoName == null) return List.nil();
if (!annoName.isEmpty()) {
- for (String bn : annotationsToFind) if (typeMatches(bn, node, anno.annotationType)) return List.of(anno);
+ for (String bn : annotationsToFind) if (typeMatches(bn, node, annoName)) return List.of(anno);
}
ListBuffer<JCAnnotation> result = new ListBuffer<JCAnnotation>();
for (JavacNode child : node.down()) {
if (child.getKind() == Kind.ANNOTATION) {
JCAnnotation annotation = (JCAnnotation) child.get();
+ String annotationTypeName = getTypeName(annotation.annotationType);
boolean match = false;
- if (!match) for (String bn : annotationsToFind) if (typeMatches(bn, node, annotation.annotationType)) {
+ if (!match) for (String bn : annotationsToFind) if (typeMatches(bn, node, annotationTypeName)) {
result.append(annotation);
break;
}