From 2d7774b9ab933b9ee306a6e33c168557447229ac Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Tue, 24 Jan 2023 17:45:51 +0000 Subject: [PATCH] HHH-16091 Optimize also AbstractStandardBasicType#compare and #fromString --- .../hibernate/type/AbstractStandardBasicType.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java b/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java index fed32e9aec..6b159d3f72 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/AbstractStandardBasicType.java @@ -12,6 +12,7 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; import java.time.ZonedDateTime; +import java.util.Comparator; import java.util.Map; import org.hibernate.Hibernate; @@ -51,6 +52,7 @@ public abstract class AbstractStandardBasicType private final AbstractClassJavaType javaTypeAsAbstractClassJavaType; private final Class javaTypeClass; private final MutabilityPlan mutabilityPlan; + private final Comparator javatypeComparator; public AbstractStandardBasicType(JdbcType jdbcType, JavaType javaType) { this.jdbcType = jdbcType; @@ -64,6 +66,7 @@ public abstract class AbstractStandardBasicType //A very simple dispatch optimisation, make these a constant: this.javaTypeClass = javaType.getJavaTypeClass(); this.mutabilityPlan = javaType.getMutabilityPlan(); + this.javatypeComparator = javaType.getComparator(); //This is a dispatch optimisation to avoid megamorphic invocations on the most common type: if ( javaType instanceof AbstractClassJavaType ) { this.javaTypeAsAbstractClassJavaType = (AbstractClassJavaType) javaType; @@ -94,7 +97,13 @@ public abstract class AbstractStandardBasicType } public T fromString(CharSequence string) { - return javaType.fromString( string ); + final AbstractClassJavaType type = this.javaTypeAsAbstractClassJavaType; + if ( type != null ) { + return type.fromString( string ); + } + else { + return javaType.fromString( string ); + } } protected MutabilityPlan getMutabilityPlan() { @@ -219,7 +228,7 @@ public abstract class AbstractStandardBasicType @Override @SuppressWarnings("unchecked") public final int compare(Object x, Object y) { - return javaType.getComparator().compare( (T) x, (T) y ); + return this.javatypeComparator.compare( (T) x, (T) y ); } @Override