changeset 728:0a22044eee9c

Optimize setBytes() implementation. For the 16 hex codes use a char[] and direct array indexing instead of a String and calling charAt().
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 02 Feb 2023 16:27:23 +0100 (2023-02-02)
parents 55c14e65b4be
children 6c9abd326ad2
files src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java
diffstat 1 files changed, 4 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java
+++ b/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java
@@ -764,7 +764,7 @@ public class MonetPreparedStatement
 		setValue(parameterIndex, Byte.toString(x));
 	}
 
-	static final String HEXES = "0123456789ABCDEF";
+	static final char[] HEXES = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
 	/**
 	 * Sets the designated parameter to the given Java array of bytes. The
 	 * driver converts this to an SQL VARBINARY or LONGVARBINARY (depending
@@ -787,8 +787,9 @@ public class MonetPreparedStatement
 		hex.append("blob '");	// add a casting prefix
 		// convert the bytes into hex codes
 		for (int i = 0; i < len; i++) {
-			hex.append(HEXES.charAt((x[i] & 0xF0) >> 4))
-			   .append(HEXES.charAt((x[i] & 0x0F)));
+			byte b = x[i];
+			hex.append(HEXES[(b & 0xF0) >> 4])
+			   .append(HEXES[(b & 0x0F)]);
 		}
 		hex.append("'");	// end of hex string value
 		setValue(parameterIndex, hex.toString());