Mercurial > hg > monetdb-java
changeset 326:aa654804af6a
Optimised setBytes() method. Eliminated the concatenation of 3 strings: "blob '" + hex.toString() + "'" which can be costly for large byte[] data, which has just been converted into hexString of twice its size.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 12 Sep 2019 17:43:02 +0200 (2019-09-12) |
parents | 0b8eb1df8276 |
children | ca6a4b02d418 |
files | src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java |
diffstat | 1 files changed, 9 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java @@ -1260,14 +1260,16 @@ public class MonetPreparedStatement return; } - final StringBuilder hex = new StringBuilder(x.length * 2); - byte b; - for (int i = 0; i < x.length; i++) { - b = x[i]; - hex.append(HEXES.charAt((b & 0xF0) >> 4)) - .append(HEXES.charAt((b & 0x0F))); + final int len = x.length; + final StringBuilder hex = new StringBuilder(8 + (len * 2)); + 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))); } - setValue(parameterIndex, "blob '" + hex.toString() + "'"); + hex.append("'"); // end of hex string value + setValue(parameterIndex, hex.toString()); } /**