Skip to content

Commit f4bdddf

Browse files
committed
Improve hasJacksonAnnotations performance with early return
Signed-off-by: stroller <[email protected]>
1 parent b452e89 commit f4bdddf

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

spring-ai-model/src/main/java/org/springframework/ai/aot/AiRuntimeHints.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,11 @@ public static Set<TypeReference> findClassesInPackage(String packageName, TypeFi
100100
}
101101

102102
private static boolean hasJacksonAnnotations(Class<?> type) {
103-
var hasAnnotation = false;
104103
var annotationsToFind = Set.of(JsonProperty.class, JsonInclude.class);
105104
for (var annotationToFind : annotationsToFind) {
106105

107106
if (type.isAnnotationPresent(annotationToFind)) {
108-
hasAnnotation = true;
107+
return true;
109108
}
110109

111110
var executables = new HashSet<Executable>();
@@ -114,35 +113,33 @@ private static boolean hasJacksonAnnotations(Class<?> type) {
114113
executables.addAll(Set.of(type.getDeclaredConstructors()));
115114

116115
for (var executable : executables) {
117-
//
118116
if (executable.isAnnotationPresent(annotationToFind)) {
119-
hasAnnotation = true;
117+
return true;
120118
}
121119

122-
///
123120
for (var p : executable.getParameters()) {
124121
if (p.isAnnotationPresent(annotationToFind)) {
125-
hasAnnotation = true;
122+
return true;
126123
}
127124
}
128125
}
129126

130127
if (type.getRecordComponents() != null) {
131128
for (var r : type.getRecordComponents()) {
132129
if (r.isAnnotationPresent(annotationToFind)) {
133-
hasAnnotation = true;
130+
return true;
134131
}
135132
}
136133
}
137134

138135
for (var f : type.getFields()) {
139136
if (f.isAnnotationPresent(annotationToFind)) {
140-
hasAnnotation = true;
137+
return true;
141138
}
142139
}
143140
}
144141

145-
return hasAnnotation;
142+
return false;
146143
}
147144

148145
private static Set<Class<?>> discoverJacksonAnnotatedTypesFromRootType(Class<?> type) {

0 commit comments

Comments
 (0)