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
This commit is contained in:
Barry Lind 2002-08-16 17:51:38 +00:00
parent ab0f98518c
commit 875364e5ff
3 changed files with 11 additions and 8 deletions

View File

@ -13,7 +13,7 @@ import org.postgresql.largeobject.*;
import org.postgresql.util.PGbytea; import org.postgresql.util.PGbytea;
import org.postgresql.util.PSQLException; 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 * This class defines methods of the jdbc1 specification. This class is
* extended by org.postgresql.jdbc2.AbstractJdbc2ResultSet which adds the jdbc2 * extended by org.postgresql.jdbc2.AbstractJdbc2ResultSet which adds the jdbc2
* methods. The real ResultSet class (for jdbc1) is org.postgresql.jdbc1.Jdbc1ResultSet * 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 first time, create the buffer, otherwise clear it.
if (rs.sbuf == null) if (rs.sbuf == null)
rs.sbuf = new StringBuffer(); rs.sbuf = new StringBuffer(32);
else else {
rs.sbuf.setLength(0); rs.sbuf.setLength(0);
}
// Copy s into sbuf for parsing. // Copy s into sbuf for parsing.
rs.sbuf.append(s); rs.sbuf.append(s);

View File

@ -8,7 +8,7 @@ import java.util.Vector;
import org.postgresql.largeobject.*; import org.postgresql.largeobject.*;
import org.postgresql.util.*; 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 * This class defines methods of the jdbc1 specification. This class is
* extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2 * extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2
* methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement * 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; private static final short ESC_TIMEDATE = 3;
// Some performance caches // Some performance caches
private StringBuffer sbuf = new StringBuffer(); private StringBuffer sbuf = new StringBuffer(32);
//Used by the preparedstatement style methods //Used by the preparedstatement style methods
protected String sql; 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 // Since escape codes can only appear in SQL CODE, we keep track
// of if we enter a string or not. // of if we enter a string or not.
StringBuffer newsql = new StringBuffer(); StringBuffer newsql = new StringBuffer(sql.length());
short state = IN_SQLCODE; short state = IN_SQLCODE;
int i = -1; int i = -1;
@ -736,6 +736,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
synchronized (sbuf) synchronized (sbuf)
{ {
sbuf.setLength(0); sbuf.setLength(0);
sbuf.ensureCapacity(x.length());
int i; int i;
sbuf.append('\''); sbuf.append('\'');
@ -852,6 +853,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
synchronized (sbuf) synchronized (sbuf)
{ {
sbuf.setLength(0); sbuf.setLength(0);
sbuf.ensureCapacity(32);
sbuf.append("'"); sbuf.append("'");
//format the timestamp //format the timestamp
//we do our own formating so that we can get a format //we do our own formating so that we can get a format

View File

@ -5,7 +5,7 @@ import java.sql.*;
/* /*
* Converts to and from the postgresql bytea datatype used by the backend. * 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 public class PGbytea
@ -62,7 +62,7 @@ public class PGbytea
{ {
if (p_buf == null) if (p_buf == null)
return 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++) for (int i = 0; i < p_buf.length; i++)
{ {
int l_int = (int)p_buf[i]; int l_int = (int)p_buf[i];