1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-27 07:42:10 +03:00

Applied patch from Teofilis Martisius to improve performance.

Also removed some unused files and fixed the which needed a small change
after the previous patch to build.xml.

 Modified Files:
 	jdbc/Makefile jdbc/org/postgresql/core/Encoding.java
 	jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java
 Removed Files:
 	jdbc/utils/CheckVersion.java jdbc/utils/buildDriver
 	jdbc/utils/changelog.pl
This commit is contained in:
Barry Lind
2002-10-20 02:55:50 +00:00
parent e9f07b14e1
commit 06b297938d
6 changed files with 55 additions and 150 deletions

View File

@@ -8,7 +8,7 @@ import org.postgresql.util.*;
/*
* Converts to and from the character encoding used by the backend.
*
* $Id: Encoding.java,v 1.6 2002/09/06 21:23:05 momjian Exp $
* $Id: Encoding.java,v 1.7 2002/10/20 02:55:50 barry Exp $
*/
public class Encoding
@@ -161,6 +161,9 @@ public class Encoding
}
else
{
if (encoding.equals("UTF-8")) {
return decodeUTF8(encodedString, offset, length);
}
return new String(encodedString, offset, length, encoding);
}
}
@@ -223,4 +226,44 @@ public class Encoding
return false;
}
}
/**
* custom byte[] -> String conversion routine, 3x-10x faster than
* standard new String(byte[])
*/
private static final int pow2_6 = 64; // 26
private static final int pow2_12 = 4096; // 212
private static char[] cdata = new char[50];
private synchronized String decodeUTF8(byte data[], int offset, int length) {
char[] l_cdata = cdata;
if (l_cdata.length < (length-offset)) {
l_cdata = new char[length-offset];
}
int i = offset;
int j = 0;
int z, y, x, val;
while (i < length) {
z = data[i] & 0xFF;
if (z < 0x80) {
l_cdata[j++] = (char)data[i];
i++;
} else if (z >= 0xE0) { // length == 3
y = data[i+1] & 0xFF;
x = data[i+2] & 0xFF;
val = (z-0xE0)*pow2_12 + (y-0x80)*pow2_6 + (x-0x80);
l_cdata[j++] = (char) val;
i+= 3;
} else { // length == 2 (maybe add checking for length > 3, throw exception if it is
y = data[i+1] & 0xFF;
val = (z - 0xC0)* (pow2_6)+(y-0x80);
l_cdata[j++] = (char) val;
i+=2;
}
}
String s = new String(l_cdata, 0, j);
return s;
}
}

View File

@@ -14,7 +14,7 @@ import org.postgresql.largeobject.LargeObjectManager;
import org.postgresql.util.*;
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.11 2002/10/17 05:33:52 barry Exp $
/* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc1/Attic/AbstractJdbc1Connection.java,v 1.12 2002/10/20 02:55:50 barry Exp $
* This class defines methods of the jdbc1 specification. This class is
* extended by org.postgresql.jdbc2.AbstractJdbc2Connection which adds the jdbc2
* methods. The real Connection class (for jdbc1) is org.postgresql.jdbc1.Jdbc1Connection
@@ -367,10 +367,16 @@ public abstract class AbstractJdbc1Connection implements org.postgresql.PGConnec
//jdbc by default assumes autocommit is on until setAutoCommit(false)
//is called. Therefore we need to ensure a new connection is
//initialized to autocommit on.
//We also set the client encoding so that the driver only needs
//to deal with utf8. We can only do this in 7.3 because multibyte
//support is now always included
if (haveMinimumServerVersion("7.3"))
{
java.sql.ResultSet acRset =
ExecSQL("show autocommit");
ExecSQL("set client_encoding = 'UNICODE'; show autocommit");
//set encoding to be unicode
encoding = Encoding.getEncoding("UNICODE", null);
if (!acRset.next())
{