HHH-18704 optimize away equals() search for records + enums

This commit is contained in:
Gavin King 2024-10-08 09:05:48 +02:00
parent 72e0f2968a
commit 9166d73f36
1 changed files with 6 additions and 0 deletions

View File

@ -117,6 +117,9 @@ public final class ReflectHelper {
* @return True if clazz defines an equals override. * @return True if clazz defines an equals override.
*/ */
public static boolean overridesEquals(Class<?> clazz) { public static boolean overridesEquals(Class<?> clazz) {
if ( clazz.isRecord() || clazz.isEnum() ) {
return true;
}
Method equals; Method equals;
try { try {
equals = extractEqualsMethod( clazz ); equals = extractEqualsMethod( clazz );
@ -134,6 +137,9 @@ public final class ReflectHelper {
* @return True if clazz defines an hashCode override. * @return True if clazz defines an hashCode override.
*/ */
public static boolean overridesHashCode(Class<?> clazz) { public static boolean overridesHashCode(Class<?> clazz) {
if ( clazz.isRecord() || clazz.isEnum() ) {
return true;
}
Method hashCode; Method hashCode;
try { try {
hashCode = extractHashCodeMethod( clazz ); hashCode = extractHashCodeMethod( clazz );