Skip to content

Commit e38c020

Browse files
committed
TypeDescriptor efficiently matches equal annotations as well
Issue: SPR-15060
1 parent 963ea06 commit e38c020

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,14 +479,19 @@ private boolean annotationsMatch(TypeDescriptor otherDesc) {
479479
}
480480
if (anns.length > 0) {
481481
for (int i = 0; i < anns.length; i++) {
482-
if (anns[i] != otherAnns[i]) {
482+
if (!annotationEquals(anns[i], otherAnns[i])) {
483483
return false;
484484
}
485485
}
486486
}
487487
return true;
488488
}
489489

490+
private boolean annotationEquals(Annotation ann, Annotation otherAnn) {
491+
// Annotation.equals is reflective and pretty slow, so let's check identity and proxy type first.
492+
return (ann == otherAnn || (ann.getClass() == otherAnn.getClass() && ann.equals(otherAnn)));
493+
}
494+
490495
@Override
491496
public int hashCode() {
492497
return getType().hashCode();

0 commit comments

Comments
 (0)