Skip to content

Commit e79d7ef

Browse files
committed
use instanceof instead of isInstance() on the hot path
surely NBD, but such an easy thing to fix and remove all doubt
1 parent 6c83e1d commit e79d7ef

35 files changed

+116
-116
lines changed

hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BlobJavaTypeDescriptor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public <X> X unwrap(Blob value, Class<X> type, WrapperOptions options) {
110110

111111
try {
112112
if ( BinaryStream.class.isAssignableFrom( type ) ) {
113-
if ( BlobImplementer.class.isInstance( value ) ) {
113+
if (value instanceof BlobImplementer) {
114114
// if the incoming Blob is a wrapper, just pass along its BinaryStream
115115
return (X) ( (BlobImplementer) value ).getUnderlyingStream();
116116
}
@@ -120,7 +120,7 @@ public <X> X unwrap(Blob value, Class<X> type, WrapperOptions options) {
120120
}
121121
}
122122
else if ( byte[].class.isAssignableFrom( type )) {
123-
if ( BlobImplementer.class.isInstance( value ) ) {
123+
if (value instanceof BlobImplementer) {
124124
// if the incoming Blob is a wrapper, just grab the bytes from its BinaryStream
125125
return (X) ( (BlobImplementer) value ).getUnderlyingStream().getBytes();
126126
}
@@ -130,7 +130,7 @@ else if ( byte[].class.isAssignableFrom( type )) {
130130
}
131131
}
132132
else if (Blob.class.isAssignableFrom( type )) {
133-
final Blob blob = WrappedBlob.class.isInstance( value )
133+
final Blob blob = value instanceof WrappedBlob
134134
? ( (WrappedBlob) value ).getWrappedBlob()
135135
: value;
136136
return (X) blob;

hibernate-core/src/main/java/org/hibernate/type/descriptor/java/BooleanJavaTypeDescriptor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,18 @@ public <X> Boolean wrap(X value, WrapperOptions options) {
8585
if ( value == null ) {
8686
return null;
8787
}
88-
if ( Boolean.class.isInstance( value ) ) {
88+
if (value instanceof Boolean) {
8989
return (Boolean) value;
9090
}
91-
if ( Number.class.isInstance( value ) ) {
91+
if (value instanceof Number) {
9292
final int intValue = ( (Number) value ).intValue();
9393
return intValue != 0;
9494
}
95-
if ( Character.class.isInstance( value ) ) {
95+
if (value instanceof Character) {
9696
return isTrue( (Character) value );
9797
}
98-
if ( String.class.isInstance( value ) ) {
99-
return isTrue((String) value);
98+
if (value instanceof String) {
99+
return isTrue( (String) value );
100100
}
101101
throw unknownWrap( value.getClass() );
102102
}

hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ByteArrayJavaTypeDescriptor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,16 @@ public <X> Byte[] wrap(X value, WrapperOptions options) {
100100
if ( value == null ) {
101101
return null;
102102
}
103-
if ( Byte[].class.isInstance( value ) ) {
103+
if (value instanceof Byte[]) {
104104
return (Byte[]) value;
105105
}
106-
if ( byte[].class.isInstance( value ) ) {
106+
if (value instanceof byte[]) {
107107
return wrapBytes( (byte[]) value );
108108
}
109-
if ( InputStream.class.isInstance( value ) ) {
109+
if (value instanceof InputStream) {
110110
return wrapBytes( DataHelper.extractBytes( (InputStream) value ) );
111111
}
112-
if ( Blob.class.isInstance( value ) || DataHelper.isNClob( value.getClass() ) ) {
112+
if ( value instanceof Blob || DataHelper.isNClob( value.getClass() ) ) {
113113
try {
114114
return wrapBytes( DataHelper.extractBytes( ( (Blob) value ).getBinaryStream() ) );
115115
}

hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarDateJavaTypeDescriptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ public <X> Calendar wrap(X value, WrapperOptions options) {
120120
if ( value == null ) {
121121
return null;
122122
}
123-
if ( Calendar.class.isInstance( value ) ) {
123+
if (value instanceof Calendar) {
124124
return (Calendar) value;
125125
}
126126

127-
if ( ! Date.class.isInstance( value ) ) {
127+
if ( !(value instanceof Date)) {
128128
throw unknownWrap( value.getClass() );
129129
}
130130

hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarJavaTypeDescriptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ public <X> Calendar wrap(X value, WrapperOptions options) {
136136
if ( value == null ) {
137137
return null;
138138
}
139-
if ( Calendar.class.isInstance( value ) ) {
139+
if (value instanceof Calendar) {
140140
return (Calendar) value;
141141
}
142142

143-
if ( ! java.util.Date.class.isInstance( value ) ) {
143+
if ( !(value instanceof java.util.Date)) {
144144
throw unknownWrap( value.getClass() );
145145
}
146146

hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CalendarTimeJavaTypeDescriptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ public <X> Calendar wrap(X value, WrapperOptions options) {
120120
if ( value == null ) {
121121
return null;
122122
}
123-
if ( Calendar.class.isInstance( value ) ) {
123+
if (value instanceof Calendar) {
124124
return (Calendar) value;
125125
}
126126

127-
if ( ! Date.class.isInstance( value ) ) {
127+
if ( !(value instanceof Date)) {
128128
throw unknownWrap( value.getClass() );
129129
}
130130

hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CharacterArrayJavaTypeDescriptor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ public <X> Character[] wrap(X value, WrapperOptions options) {
8181
if ( value == null ) {
8282
return null;
8383
}
84-
if ( Character[].class.isInstance( value ) ) {
84+
if (value instanceof Character[]) {
8585
return (Character[]) value;
8686
}
87-
if ( String.class.isInstance( value ) ) {
87+
if (value instanceof String) {
8888
return wrapChars( ( (String) value ).toCharArray() );
8989
}
90-
if ( Clob.class.isInstance( value ) ) {
90+
if (value instanceof Clob) {
9191
return wrapChars( DataHelper.extractString( ( (Clob) value ) ).toCharArray() );
9292
}
93-
if ( Reader.class.isInstance( value ) ) {
93+
if (value instanceof Reader) {
9494
return wrapChars( DataHelper.extractString( (Reader) value ).toCharArray() );
9595
}
9696
throw unknownWrap( value.getClass() );

hibernate-core/src/main/java/org/hibernate/type/descriptor/java/CharacterJavaTypeDescriptor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ public <X> Character wrap(X value, WrapperOptions options) {
5959
if ( value == null ) {
6060
return null;
6161
}
62-
if ( Character.class.isInstance( value ) ) {
62+
if (value instanceof Character) {
6363
return (Character) value;
6464
}
65-
if ( String.class.isInstance( value ) ) {
65+
if (value instanceof String) {
6666
final String str = (String) value;
6767
return str.charAt( 0 );
6868
}
69-
if ( Number.class.isInstance( value ) ) {
69+
if (value instanceof Number) {
7070
final Number nbr = (Number) value;
7171
return (char) nbr.shortValue();
7272
}

hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ClassJavaTypeDescriptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public <X> Class wrap(X value, WrapperOptions options) {
5656
if ( value == null ) {
5757
return null;
5858
}
59-
if ( Class.class.isInstance( value ) ) {
59+
if (value instanceof Class) {
6060
return (Class) value;
6161
}
62-
if ( CharSequence.class.isInstance( value ) ) {
62+
if (value instanceof CharSequence) {
6363
return fromString( (CharSequence) value );
6464
}
6565
throw unknownWrap( value.getClass() );

hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ClobJavaTypeDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public <X> X unwrap(final Clob value, Class<X> type, WrapperOptions options) {
9797
}
9898
}
9999
else if ( String.class.isAssignableFrom( type ) ) {
100-
if ( ClobImplementer.class.isInstance( value ) ) {
100+
if (value instanceof ClobImplementer) {
101101
// if the incoming Clob is a wrapper, just grab the bytes from its BinaryStream
102102
return (X) ( (ClobImplementer) value ).getUnderlyingStream().asString();
103103
}

0 commit comments

Comments
 (0)