From 875364e5ffd1027d16ac36f188cd3c5acdf3067c Mon Sep 17 00:00:00 2001 From: Barry Lind Date: Fri, 16 Aug 2002 17:51:38 +0000 Subject: [PATCH] Performance tweaks to StringBuffer suggested by hhaag@gmx.de Modified Files: jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java jdbc/org/postgresql/util/PGbytea.java --- .../jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java | 7 ++++--- .../jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java | 8 +++++--- src/interfaces/jdbc/org/postgresql/util/PGbytea.java | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java index e3e75c1e19..ddec830c4c 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java @@ -13,7 +13,7 @@ import org.postgresql.largeobject.*; import org.postgresql.util.PGbytea; import org.postgresql.util.PSQLException; -/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.3 2002/08/14 20:35:39 barry Exp $ +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.4 2002/08/16 17:51:38 barry Exp $ * This class defines methods of the jdbc1 specification. This class is * extended by org.postgresql.jdbc2.AbstractJdbc2ResultSet which adds the jdbc2 * methods. The real ResultSet class (for jdbc1) is org.postgresql.jdbc1.Jdbc1ResultSet @@ -851,9 +851,10 @@ public abstract class AbstractJdbc1ResultSet // If first time, create the buffer, otherwise clear it. if (rs.sbuf == null) - rs.sbuf = new StringBuffer(); - else + rs.sbuf = new StringBuffer(32); + else { rs.sbuf.setLength(0); + } // Copy s into sbuf for parsing. rs.sbuf.append(s); diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java index 96a50efa8f..fc532fcc8b 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java @@ -8,7 +8,7 @@ import java.util.Vector; import org.postgresql.largeobject.*; import org.postgresql.util.*; -/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.3 2002/07/25 22:45:27 barry Exp $ +/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.4 2002/08/16 17:51:38 barry Exp $ * This class defines methods of the jdbc1 specification. This class is * extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2 * methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement @@ -40,7 +40,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme private static final short ESC_TIMEDATE = 3; // Some performance caches - private StringBuffer sbuf = new StringBuffer(); + private StringBuffer sbuf = new StringBuffer(32); //Used by the preparedstatement style methods protected String sql; @@ -498,7 +498,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme { // Since escape codes can only appear in SQL CODE, we keep track // of if we enter a string or not. - StringBuffer newsql = new StringBuffer(); + StringBuffer newsql = new StringBuffer(sql.length()); short state = IN_SQLCODE; int i = -1; @@ -736,6 +736,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme synchronized (sbuf) { sbuf.setLength(0); + sbuf.ensureCapacity(x.length()); int i; sbuf.append('\''); @@ -852,6 +853,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme synchronized (sbuf) { sbuf.setLength(0); + sbuf.ensureCapacity(32); sbuf.append("'"); //format the timestamp //we do our own formating so that we can get a format diff --git a/src/interfaces/jdbc/org/postgresql/util/PGbytea.java b/src/interfaces/jdbc/org/postgresql/util/PGbytea.java index 93e8afae5a..a6d1c011bf 100644 --- a/src/interfaces/jdbc/org/postgresql/util/PGbytea.java +++ b/src/interfaces/jdbc/org/postgresql/util/PGbytea.java @@ -5,7 +5,7 @@ import java.sql.*; /* * Converts to and from the postgresql bytea datatype used by the backend. * - * $Id: PGbytea.java,v 1.4 2002/01/05 22:26:23 barry Exp $ + * $Id: PGbytea.java,v 1.5 2002/08/16 17:51:38 barry Exp $ */ public class PGbytea @@ -62,7 +62,7 @@ public class PGbytea { if (p_buf == null) return null; - StringBuffer l_strbuf = new StringBuffer(); + StringBuffer l_strbuf = new StringBuffer(p_buf.length); for (int i = 0; i < p_buf.length; i++) { int l_int = (int)p_buf[i];