Skip to content

Commit 4cf9b5c

Browse files
committed
GH-1149 - Optimize performance for application module lookups by type.
We now avoid immediately resorting to a by type name lookup that triggers extensive search to be able to support simple class names.
1 parent b932faf commit 4cf9b5c

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ public ArchitecturallyEvidentType getArchitecturallyEvidentType(Class<?> type) {
341341
* @param type must not be {@literal null}.
342342
*/
343343
public boolean contains(JavaClass type) {
344-
return contains(type.getName());
344+
return classes.contains(type);
345345
}
346346

347347
/**
@@ -350,7 +350,7 @@ public boolean contains(JavaClass type) {
350350
* @param type must not be {@literal null}.
351351
*/
352352
public boolean contains(Class<?> type) {
353-
return contains(type.getName());
353+
return classes.contains(type);
354354
}
355355

356356
/**

spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModules.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,10 @@ public Optional<ApplicationModule> getModuleByType(String candidate) {
412412
* @return will never be {@literal null}.
413413
*/
414414
public Optional<ApplicationModule> getModuleByType(Class<?> candidate) {
415-
return getModuleByType(candidate.getName());
415+
416+
return allModules()
417+
.filter(it -> it.contains(candidate))
418+
.findFirst();
416419
}
417420

418421
/**

spring-modulith-core/src/main/java/org/springframework/modulith/core/Classes.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,11 @@ Optional<JavaClass> toOptional() {
172172
}
173173

174174
boolean contains(JavaClass type) {
175-
return !that(new SameClass(type)).isEmpty();
175+
return classes.contains(type);
176+
}
177+
178+
boolean contains(Class<?> type) {
179+
return classes.stream().anyMatch(it -> it.isEquivalentTo(type));
176180
}
177181

178182
boolean contains(String className) {

0 commit comments

Comments
 (0)