Skip to content

Commit f51779d

Browse files
committed
HHH-7066 byte arrays to String conversion benefits from initial buffer size
1 parent 98d0b83 commit f51779d

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ public static String extractString(Reader reader) {
7373
*/
7474
public static String extractString(Reader reader, int lengthHint) {
7575
// read the Reader contents into a buffer and return the complete string
76-
final StringBuilder stringBuilder = new StringBuilder( lengthHint );
76+
final int bufferSize = Math.min( lengthHint, 2048 );
77+
final StringBuilder stringBuilder = new StringBuilder( bufferSize );
7778
try {
78-
final int bufferSize = Math.min( lengthHint, 2048 );
7979
char[] buffer = new char[bufferSize];
8080
while (true) {
8181
int amountRead = reader.read( buffer, 0, bufferSize );

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public int extractHashCode(byte[] bytes) {
6262
}
6363

6464
public String toString(byte[] bytes) {
65-
final StringBuffer buf = new StringBuffer();
65+
final StringBuilder buf = new StringBuilder( bytes.length * 2 );
6666
for ( byte aByte : bytes ) {
6767
final String hexStr = Integer.toHexString( aByte - Byte.MIN_VALUE );
6868
if ( hexStr.length() == 1 ) {

0 commit comments

Comments
 (0)