From bde7362d9c13278ae87f7c3b85ccc2bac4a04585 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Thu, 3 Nov 2022 17:21:31 +0000 Subject: [PATCH] HHH-15634 Extracting reusable Type constants from ByteBuddy InlineDirtyCheckingHandler --- .../bytebuddy/InlineDirtyCheckingHandler.java | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/bytebuddy/InlineDirtyCheckingHandler.java b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/bytebuddy/InlineDirtyCheckingHandler.java index 4330673685..34847c8c4a 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/bytebuddy/InlineDirtyCheckingHandler.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/bytebuddy/InlineDirtyCheckingHandler.java @@ -32,6 +32,11 @@ import net.bytebuddy.jar.asm.Type; final class InlineDirtyCheckingHandler implements Implementation, ByteCodeAppender { + private static final String HELPER_TYPE_NAME = Type.getInternalName( InlineDirtyCheckerEqualsHelper.class ); + private static final Type PE_INTERCEPTABLE_TYPE = Type.getType( PersistentAttributeInterceptable.class ); + private static final Type OBJECT_TYPE = Type.getType( Object.class ); + private static final Type STRING_TYPE = Type.getType( String.class ); + private final Implementation delegate; private final TypeDescription managedCtClass; @@ -137,16 +142,17 @@ final class InlineDirtyCheckingHandler implements Implementation, ByteCodeAppend int branchCode; if ( applyLazyCheck ) { if ( persistentField.getType().isPrimitive() ) { + final Type fieldType = Type.getType( persistentField.getDescriptor() ); methodVisitor.visitMethodInsn( Opcodes.INVOKESTATIC, - Type.getInternalName( InlineDirtyCheckerEqualsHelper.class ), + HELPER_TYPE_NAME, "areEquals", Type.getMethodDescriptor( - Type.getType( boolean.class ), - Type.getType( PersistentAttributeInterceptable.class ), - Type.getType( String.class ), - Type.getType( persistentField.getDescriptor() ), - Type.getType( persistentField.getDescriptor() ) + Type.BOOLEAN_TYPE, + PE_INTERCEPTABLE_TYPE, + STRING_TYPE, + fieldType, + fieldType ), false ); @@ -154,14 +160,14 @@ final class InlineDirtyCheckingHandler implements Implementation, ByteCodeAppend else { methodVisitor.visitMethodInsn( Opcodes.INVOKESTATIC, - Type.getInternalName( InlineDirtyCheckerEqualsHelper.class ), + HELPER_TYPE_NAME, "areEquals", Type.getMethodDescriptor( - Type.getType( boolean.class ), - Type.getType( PersistentAttributeInterceptable.class ), - Type.getType( String.class ), - Type.getType( Object.class ), - Type.getType( Object.class ) + Type.BOOLEAN_TYPE, + PE_INTERCEPTABLE_TYPE, + STRING_TYPE, + OBJECT_TYPE, + OBJECT_TYPE ), false ); @@ -190,9 +196,9 @@ final class InlineDirtyCheckingHandler implements Implementation, ByteCodeAppend Type.getInternalName( Objects.class ), "deepEquals", Type.getMethodDescriptor( - Type.getType( boolean.class ), - Type.getType( Object.class ), - Type.getType( Object.class ) + Type.BOOLEAN_TYPE, + OBJECT_TYPE, + OBJECT_TYPE ), false ); @@ -208,7 +214,7 @@ final class InlineDirtyCheckingHandler implements Implementation, ByteCodeAppend Opcodes.INVOKEVIRTUAL, managedCtClass.getInternalName(), EnhancerConstants.TRACKER_CHANGER_NAME, - Type.getMethodDescriptor( Type.getType( void.class ), Type.getType( String.class ) ), + Type.getMethodDescriptor( Type.VOID_TYPE, STRING_TYPE ), false ); // }