--- /home/lvflores/Desktop/postgresql-jdbc-8.1-407.src/org/postgresql/util/PGbytea.java	2005-01-11 08:25:49.000000000 +0000
+++ PGbytea.java	2006-08-22 23:37:53.000000000 +0100
@@ -16,8 +16,9 @@
  */
 public class PGbytea
 {
-
-    /*
+	private static final int MAX_3_BUFF_SIZE = 0; 
+	
+	/*
      * Converts a PG bytea raw value (i.e. the raw binary representation
      * of the bytea data type) into a java byte[]
      */
@@ -25,8 +26,36 @@
     {
         if (s == null)
             return null;
-        int slength = s.length;
-        byte[] buf = new byte[slength];
+        final int slength = s.length;
+		byte[] buf = null;
+		int correctSize = slength;
+		if (slength > MAX_3_BUFF_SIZE)
+		{
+//			long l = System.currentTimeMillis();
+			// count / * //
+			for (int i = 0; i < slength; ++i)
+			{
+				byte current = s[i];
+				if (current == '\\')
+				{
+					byte next = s[ ++i ];
+					if (next == '\\')
+					{
+						--correctSize;
+					}
+					else
+					{
+						correctSize -= 3;
+					}
+				}
+			}
+//System.out.println( "TOOK: " + ( System.currentTimeMillis() - l ) + "ms - SAVED " + ( slength - correctSize ) + " ON SECOND BUFFER" );
+			buf = new byte[correctSize];
+		}
+		else
+		{
+			buf = new byte[slength];
+		}
         int bufpos = 0;
         int thebyte;
         byte nextbyte;
@@ -55,6 +84,11 @@
                 buf[bufpos++] = nextbyte;
             }
         }
+		if (bufpos == correctSize)
+		{
+//System.out.println( "SKIPPED LAST BUFFER" );
+			return buf;
+		}
         byte[] l_return = new byte[bufpos];
         System.arraycopy(buf, 0, l_return, 0, bufpos);
         return l_return;
@@ -103,6 +137,4 @@
         }
         return l_strbuf.toString();
     }
-
-
 }
