Efficient type plus annotation comparisons during converter retrieval

Issue: SPR-14926
Issue: SPR-12926
This commit is contained in:
Juergen Hoeller
2016-11-30 22:22:44 +01:00
parent ac5933a7ac
commit f6b8b84df9
3 changed files with 71 additions and 40 deletions

View File

@@ -52,11 +52,9 @@ public class FormattingConversionService extends GenericConversionService
private StringValueResolver embeddedValueResolver;
private final Map<AnnotationConverterKey, GenericConverter> cachedPrinters =
new ConcurrentHashMap<>(64);
private final Map<AnnotationConverterKey, GenericConverter> cachedPrinters = new ConcurrentHashMap<>(64);
private final Map<AnnotationConverterKey, GenericConverter> cachedParsers =
new ConcurrentHashMap<>(64);
private final Map<AnnotationConverterKey, GenericConverter> cachedParsers = new ConcurrentHashMap<>(64);
@Override
@@ -231,6 +229,7 @@ public class FormattingConversionService extends GenericConversionService
public AnnotationPrinterConverter(Class<? extends Annotation> annotationType,
AnnotationFormatterFactory<?> annotationFormatterFactory, Class<?> fieldType) {
this.annotationType = annotationType;
this.annotationFormatterFactory = annotationFormatterFactory;
this.fieldType = fieldType;
@@ -284,6 +283,7 @@ public class FormattingConversionService extends GenericConversionService
public AnnotationParserConverter(Class<? extends Annotation> annotationType,
AnnotationFormatterFactory<?> annotationFormatterFactory, Class<?> fieldType) {
this.annotationType = annotationType;
this.annotationFormatterFactory = annotationFormatterFactory;
this.fieldType = fieldType;
@@ -350,16 +350,13 @@ public class FormattingConversionService extends GenericConversionService
if (this == other) {
return true;
}
if (!(other instanceof AnnotationConverterKey)) {
return false;
}
AnnotationConverterKey otherKey = (AnnotationConverterKey) other;
return (this.annotation.equals(otherKey.annotation) && this.fieldType.equals(otherKey.fieldType));
return (this.fieldType == otherKey.fieldType && this.annotation.equals(otherKey.annotation));
}
@Override
public int hashCode() {
return (this.annotation.hashCode() + 29 * this.fieldType.hashCode());
return (this.fieldType.hashCode() * 29 + this.annotation.hashCode());
}
}