From f736fdb0222ded716bd4f0cdddc06158773d9bc1 Mon Sep 17 00:00:00 2001 From: Barry Lind Date: Tue, 20 Aug 2002 04:26:02 +0000 Subject: [PATCH] Removed code that is no longer used and has been commented out for the last two releases. Modified Files: jdbc/org/postgresql/Driver.java.in jdbc/org/postgresql/PG_Stream.java Removed Files: jdbc/org/postgresql/core/BytePoolDim1.java jdbc/org/postgresql/core/BytePoolDim2.java jdbc/org/postgresql/core/MemoryPool.java jdbc/org/postgresql/core/ObjectPool.java jdbc/org/postgresql/core/SimpleObjectPool.java --- .../jdbc/org/postgresql/Driver.java.in | 2 +- .../jdbc/org/postgresql/PG_Stream.java | 11 +- .../org/postgresql/core/BytePoolDim1.java | 100 ----------------- .../org/postgresql/core/BytePoolDim2.java | 69 ------------ .../jdbc/org/postgresql/core/MemoryPool.java | 19 ---- .../jdbc/org/postgresql/core/ObjectPool.java | 49 -------- .../org/postgresql/core/SimpleObjectPool.java | 106 ------------------ 7 files changed, 5 insertions(+), 351 deletions(-) delete mode 100644 src/interfaces/jdbc/org/postgresql/core/BytePoolDim1.java delete mode 100644 src/interfaces/jdbc/org/postgresql/core/BytePoolDim2.java delete mode 100644 src/interfaces/jdbc/org/postgresql/core/MemoryPool.java delete mode 100644 src/interfaces/jdbc/org/postgresql/core/ObjectPool.java delete mode 100644 src/interfaces/jdbc/org/postgresql/core/SimpleObjectPool.java diff --git a/src/interfaces/jdbc/org/postgresql/Driver.java.in b/src/interfaces/jdbc/org/postgresql/Driver.java.in index 009ac6100e..7d2ad9f100 100644 --- a/src/interfaces/jdbc/org/postgresql/Driver.java.in +++ b/src/interfaces/jdbc/org/postgresql/Driver.java.in @@ -442,6 +442,6 @@ public class Driver implements java.sql.Driver } //The build number should be incremented for every new build - private static int m_buildNumber = 103; + private static int m_buildNumber = 104; } diff --git a/src/interfaces/jdbc/org/postgresql/PG_Stream.java b/src/interfaces/jdbc/org/postgresql/PG_Stream.java index 9a85df8a25..11781dba96 100644 --- a/src/interfaces/jdbc/org/postgresql/PG_Stream.java +++ b/src/interfaces/jdbc/org/postgresql/PG_Stream.java @@ -10,7 +10,7 @@ import org.postgresql.core.*; import org.postgresql.util.*; /* - * $Id: PG_Stream.java,v 1.16 2001/11/19 23:16:45 momjian Exp $ + * $Id: PG_Stream.java,v 1.17 2002/08/20 04:26:02 barry Exp $ * * This class is used by Connection & PGlobj for communicating with the * backend. @@ -25,9 +25,6 @@ public class PG_Stream private BufferedOutputStream pg_output; private byte[] byte_buf = new byte[8*1024]; - BytePoolDim1 bytePoolDim1 = new BytePoolDim1(); - BytePoolDim2 bytePoolDim2 = new BytePoolDim2(); - /* * Constructor: Connect to the PostgreSQL back end and return * a stream connection. @@ -69,7 +66,7 @@ public class PG_Stream */ public void SendInteger(int val, int siz) throws IOException { - byte[] buf = bytePoolDim1.allocByte(siz); + byte[] buf = new byte[siz]; while (siz-- > 0) { @@ -272,7 +269,7 @@ public class PG_Stream { int i, bim = (nf + 7) / 8; byte[] bitmask = Receive(bim); - byte[][] answer = bytePoolDim2.allocByte(nf); + byte[][] answer = new byte[nf][0]; int whichbit = 0x80; int whichbyte = 0; @@ -310,7 +307,7 @@ public class PG_Stream */ private byte[] Receive(int siz) throws SQLException { - byte[] answer = bytePoolDim1.allocByte(siz); + byte[] answer = new byte[siz]; Receive(answer, 0, siz); return answer; } diff --git a/src/interfaces/jdbc/org/postgresql/core/BytePoolDim1.java b/src/interfaces/jdbc/org/postgresql/core/BytePoolDim1.java deleted file mode 100644 index e879a5ed76..0000000000 --- a/src/interfaces/jdbc/org/postgresql/core/BytePoolDim1.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.postgresql.core; - -/* - * A simple and efficient class to pool one dimensional byte arrays - * of different sizes. - */ -public class BytePoolDim1 -{ - /* - * The maximum size of the array we manage. - */ - int maxsize = 256; - /* - * The pools not currently in use - */ - ObjectPool notusemap[] = new ObjectPool[maxsize + 1]; - /* - * The pools currently in use - */ - ObjectPool inusemap[] = new ObjectPool[maxsize + 1]; - /* - * - */ - byte binit[][] = new byte[maxsize + 1][0]; - - /* - * Construct a new pool - */ - public BytePoolDim1() - { - for (int i = 0; i <= maxsize; i++) - { - binit[i] = new byte[i]; - inusemap[i] = new SimpleObjectPool(); - notusemap[i] = new SimpleObjectPool(); - } - } - - /* - * Allocate a byte[] of a specified size and put it in the pool. If it's - * larger than maxsize then it is not pooled. - * @return the byte[] allocated - */ - public byte[] allocByte(int size) - { - // for now until the bug can be removed - return new byte[size]; - /* - // Don't pool if >maxsize - if (size > maxsize){ - return new byte[size]; - } - - ObjectPool not_usel = notusemap[size]; - ObjectPool in_usel = inusemap[size]; - byte b[] = null; - - // Fetch from the unused pool if available otherwise allocate a new - // now array - if (!not_usel.isEmpty()) { - Object o = not_usel.remove(); - b = (byte[]) o; - } else - b = new byte[size]; - in_usel.add(b); - - return b; - */ - } - - /* - * Release an array - * @param b byte[] to release - */ - public void release(byte[] b) - { - // If it's larger than maxsize then we don't touch it - if (b.length > maxsize) - return; - - ObjectPool not_usel = notusemap[b.length]; - ObjectPool in_usel = inusemap[b.length]; - - in_usel.remove(b); - not_usel.add(b); - } - - /* - * Deallocate all - * @deprecated Real bad things happen if this is called! - */ - public void deallocate() - { - //for(int i = 0; i <= maxsize; i++){ - // notusemap[i].addAll(inusemap[i]); - // inusemap[i].clear(); - //} - } -} - diff --git a/src/interfaces/jdbc/org/postgresql/core/BytePoolDim2.java b/src/interfaces/jdbc/org/postgresql/core/BytePoolDim2.java deleted file mode 100644 index 963320070d..0000000000 --- a/src/interfaces/jdbc/org/postgresql/core/BytePoolDim2.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.postgresql.core; - -public class BytePoolDim2 -{ - int maxsize = 32; - ObjectPool notusemap[] = new ObjectPool[maxsize + 1]; - ObjectPool inusemap[] = new ObjectPool[maxsize + 1]; - - public BytePoolDim2() - { - for (int i = 0; i <= maxsize; i++) - { - inusemap[i] = new SimpleObjectPool(); - notusemap[i] = new SimpleObjectPool(); - } - } - - public byte[][] allocByte(int size) - { - // For now until the bug can be removed - return new byte[size][0]; - /* - if (size > maxsize){ - return new byte[size][0]; - } - ObjectPool not_usel = notusemap[size]; - ObjectPool in_usel = inusemap[size]; - - byte b[][] = null; - - if (!not_usel.isEmpty()) { - Object o = not_usel.remove(); - b = (byte[][]) o; - } else - b = new byte[size][0]; - in_usel.add(b); - return b; - */ - } - - public void release(byte[][] b) - { - if (b.length > maxsize) - { - return; - } - ObjectPool not_usel = notusemap[b.length]; - ObjectPool in_usel = inusemap[b.length]; - - in_usel.remove(b); - not_usel.add(b); - } - - /* - * Deallocate the object cache. - * PM 17/01/01: Commented out this code as it blows away any hope of - * multiple queries on the same connection. I'll redesign the allocation - * code to use some form of Statement context, so the buffers are per - * Statement and not per Connection/PG_Stream as it is now. - */ - public void deallocate() - { - //for(int i = 0; i <= maxsize; i++){ - // notusemap[i].addAll(inusemap[i]); - // inusemap[i].clear(); - //} - } -} - diff --git a/src/interfaces/jdbc/org/postgresql/core/MemoryPool.java b/src/interfaces/jdbc/org/postgresql/core/MemoryPool.java deleted file mode 100644 index 3f0c2cb51d..0000000000 --- a/src/interfaces/jdbc/org/postgresql/core/MemoryPool.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.postgresql.core; - -/* - * This interface defines the methods to access the memory pool classes. - */ -public interface MemoryPool -{ - /* - * Allocate an array from the pool - * @return byte[] allocated - */ - public byte[] allocByte(int size); - - /* - * Frees an object back to the pool - * @param o Object to release - */ - public void release(Object o); -} diff --git a/src/interfaces/jdbc/org/postgresql/core/ObjectPool.java b/src/interfaces/jdbc/org/postgresql/core/ObjectPool.java deleted file mode 100644 index 341bba2024..0000000000 --- a/src/interfaces/jdbc/org/postgresql/core/ObjectPool.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.postgresql.core; - -/* - * This interface defines methods needed to implement a simple object pool. - * There are two known classes that implement this, one for jdk1.1 and the - * other for jdk1.2+ - */ - -public interface ObjectPool -{ - /* - * Adds an object to the pool - * @param o Object to add - */ - public void add(Object o); - - /* - * Removes an object from the pool - * @param o Object to remove - */ - public void remove(Object o); - - /* - * Removes the top object from the pool - * @return Object from the top. - */ - public Object remove(); - - /* - * @return true if the pool is empty - */ - public boolean isEmpty(); - - /* - * @return the number of objects in the pool - */ - public int size(); - - /* - * Adds all objects in one pool to this one - * @param pool The pool to take the objects from - */ - public void addAll(ObjectPool pool); - - /* - * Clears the pool of all objects - */ - public void clear(); -} diff --git a/src/interfaces/jdbc/org/postgresql/core/SimpleObjectPool.java b/src/interfaces/jdbc/org/postgresql/core/SimpleObjectPool.java deleted file mode 100644 index d64126456d..0000000000 --- a/src/interfaces/jdbc/org/postgresql/core/SimpleObjectPool.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.postgresql.core; - -/* - * A simple and fast object pool implementation that can pool objects - * of any type. This implementation is not thread safe, it is up to the users - * of this class to assure thread safety. - */ - -public class SimpleObjectPool implements ObjectPool -{ - // This was originally in PG_Stream but moved out to fix the major problem - // where more than one query (usually all the time) overwrote the results - // of another query. - int cursize = 0; - int maxsize = 16; - Object arr[] = new Object[maxsize]; - - /* - * Adds an object to the pool - * @param o Object to add - */ - public void add(Object o) - { - if (cursize >= maxsize) - { - Object newarr[] = new Object[maxsize * 2]; - System.arraycopy(arr, 0, newarr, 0, maxsize); - maxsize = maxsize * 2; - arr = newarr; - } - arr[cursize++] = o; - } - - /* - * Removes the top object from the pool - * @return Object from the top. - */ - public Object remove() - { - return arr[--cursize]; - } - - /* - * Removes the given object from the pool - * @param o Object to remove - */ - public void remove(Object o) - { - int p = 0; - while (p < cursize && !arr[p].equals(o)) - p++; - if (arr[p].equals(o)) - { - // This should be ok as there should be no overlap conflict - System.arraycopy(arr, p + 1, arr, p, cursize - p); - cursize--; - } - } - - /* - * @return true if the pool is empty - */ - public boolean isEmpty() - { - return cursize == 0; - } - - /* - * @return the number of objects in the pool - */ - public int size() - { - return cursize; - } - - /* - * Adds all objects in one pool to this one - * @param pool The pool to take the objects from - */ - public void addAll(ObjectPool p) - { - SimpleObjectPool pool = (SimpleObjectPool)p; - - int srcsize = pool.size(); - if (srcsize == 0) - return; - int totalsize = srcsize + cursize; - if (totalsize > maxsize) - { - Object newarr[] = new Object[totalsize * 2]; - System.arraycopy(arr, 0, newarr, 0, cursize); - maxsize = maxsize = totalsize * 2; - arr = newarr; - } - System.arraycopy(pool.arr, 0, arr, cursize, srcsize); - cursize = totalsize; - } - - /* - * Clears the pool of all objects - */ - public void clear() - { - cursize = 0; - } -}