Skip to content

Commit 875364e

Browse files
author
Barry Lind
committed
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
1 parent ab0f985 commit 875364e

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import org.postgresql.util.PGbytea;
1414
import org.postgresql.util.PSQLException;
1515

16-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.3 2002/08/14 20:35:39 barry Exp $
16+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1ResultSet.java,v 1.4 2002/08/16 17:51:38 barry Exp $
1717
* This class defines methods of the jdbc1 specification. This class is
1818
* extended by org.postgresql.jdbc2.AbstractJdbc2ResultSet which adds the jdbc2
1919
* methods. The real ResultSet class (for jdbc1) is org.postgresql.jdbc1.Jdbc1ResultSet
@@ -851,9 +851,10 @@ public static Timestamp toTimestamp(String s, java.sql.ResultSet resultSet, Stri
851851

852852
// If first time, create the buffer, otherwise clear it.
853853
if (rs.sbuf == null)
854-
rs.sbuf = new StringBuffer();
855-
else
854+
rs.sbuf = new StringBuffer(32);
855+
else {
856856
rs.sbuf.setLength(0);
857+
}
857858

858859
// Copy s into sbuf for parsing.
859860
rs.sbuf.append(s);

src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import org.postgresql.largeobject.*;
99
import org.postgresql.util.*;
1010

11-
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.3 2002/07/25 22:45:27 barry Exp $
11+
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Statement.java,v 1.4 2002/08/16 17:51:38 barry Exp $
1212
* This class defines methods of the jdbc1 specification. This class is
1313
* extended by org.postgresql.jdbc2.AbstractJdbc2Statement which adds the jdbc2
1414
* methods. The real Statement class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Statement
@@ -40,7 +40,7 @@ public abstract class AbstractJdbc1Statement implements org.postgresql.PGStateme
4040
private static final short ESC_TIMEDATE = 3;
4141

4242
// Some performance caches
43-
private StringBuffer sbuf = new StringBuffer();
43+
private StringBuffer sbuf = new StringBuffer(32);
4444

4545
//Used by the preparedstatement style methods
4646
protected String sql;
@@ -498,7 +498,7 @@ protected static String escapeSQL(String sql)
498498
{
499499
// Since escape codes can only appear in SQL CODE, we keep track
500500
// of if we enter a string or not.
501-
StringBuffer newsql = new StringBuffer();
501+
StringBuffer newsql = new StringBuffer(sql.length());
502502
short state = IN_SQLCODE;
503503

504504
int i = -1;
@@ -736,6 +736,7 @@ public void setString(int parameterIndex, String x) throws SQLException
736736
synchronized (sbuf)
737737
{
738738
sbuf.setLength(0);
739+
sbuf.ensureCapacity(x.length());
739740
int i;
740741

741742
sbuf.append('\'');
@@ -852,6 +853,7 @@ public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException
852853
synchronized (sbuf)
853854
{
854855
sbuf.setLength(0);
856+
sbuf.ensureCapacity(32);
855857
sbuf.append("'");
856858
//format the timestamp
857859
//we do our own formating so that we can get a format

src/interfaces/jdbc/org/postgresql/util/PGbytea.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/*
66
* Converts to and from the postgresql bytea datatype used by the backend.
77
*
8-
* $Id: PGbytea.java,v 1.4 2002/01/05 22:26:23 barry Exp $
8+
* $Id: PGbytea.java,v 1.5 2002/08/16 17:51:38 barry Exp $
99
*/
1010

1111
public class PGbytea
@@ -62,7 +62,7 @@ public static String toPGString(byte[] p_buf) throws SQLException
6262
{
6363
if (p_buf == null)
6464
return null;
65-
StringBuffer l_strbuf = new StringBuffer();
65+
StringBuffer l_strbuf = new StringBuffer(p_buf.length);
6666
for (int i = 0; i < p_buf.length; i++)
6767
{
6868
int l_int = (int)p_buf[i];

0 commit comments

Comments
 (0)