From e051df91a0571676c6230215bdebe23360289994 Mon Sep 17 00:00:00 2001 From: Christoph Dreis Date: Tue, 21 Feb 2023 08:27:05 +0100 Subject: Reduce allocations from JavacHandlerUtil.typeMatches() --- src/core/lombok/javac/handlers/JavacHandlerUtil.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index 9c6e0f84..78c7caf5 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -1735,6 +1735,26 @@ public class JavacHandlerUtil { * Searches the given field node for annotations that are in the given list, and returns those. */ private static List findAnnotationsInList(JavacNode node, java.util.List annotationsToFind) { + JCAnnotation anno = null; + String annoName = null; + for (JavacNode child : node.down()) { + if (child.getKind() == Kind.ANNOTATION) { + if (anno != null) { + annoName = ""; + break; + } + JCAnnotation annotation = (JCAnnotation) child.get(); + annoName = annotation.annotationType.toString(); + anno = annotation; + } + } + + if (annoName == null) return List.nil(); + + if (!annoName.isEmpty()) { + for (String bn : annotationsToFind) if (typeMatches(bn, node, annoName)) return List.of(anno); + } + ListBuffer result = new ListBuffer(); for (JavacNode child : node.down()) { if (child.getKind() == Kind.ANNOTATION) { -- cgit