MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Vladislav Vaintroub Date:July 28 2010 2:07pm
Subject:bzr commit into connector-net-6.1 branch (vvaintroub:834)
View as plain text  
#At file:///H:/connector_net/6.1/ based on revid:vvaintroub@stripped

  834 Vladislav Vaintroub	2010-07-28 [merge]
      merge

    modified:
      CHANGES
      MySql.Data/Provider/Source/CompressedStream.cs
=== modified file 'CHANGES'
--- a/CHANGES	2010-07-27 21:44:04 +0000
+++ b/CHANGES	2010-07-28 14:07:01 +0000
@@ -1,4 +1,6 @@
-- Improve performance of MySqlHelper.EscapeString() (Bug#48243)
+- Improve performance of write operations (e.g insert) if compression is enabled
+  (Bug #48243)
+- Improve performance of MySqlHelper.EscapeString()
 - Fix membership provider creation failure, when default database character set is different from latin1 (Bug #53174)
 - Fix "Connection must be valid and open" exception When UpdateBatchSize > 1 
   and MySqlDataAdapter is not using an open connection (Bug #38411)

=== modified file 'MySql.Data/Provider/Source/CompressedStream.cs'
--- a/MySql.Data/Provider/Source/CompressedStream.cs	2009-07-30 13:13:25 +0000
+++ b/MySql.Data/Provider/Source/CompressedStream.cs	2010-07-28 14:07:01 +0000
@@ -209,35 +209,40 @@ namespace MySql.Data.MySqlClient
 
             // now we set our compressed and uncompressed lengths
             // based on if our compression is going to help or not
+            MemoryStream memStream;
+
             if (compressedBuffer == null)
             {
                 compressedLength = cache.Length;
                 uncompressedLength = 0;
+                memStream = cache;
             }
             else
             {
                 compressedLength = compressedBuffer.Length;
                 uncompressedLength = cache.Length;
+                memStream = compressedBuffer;
             }
 
-            baseStream.WriteByte((byte) (compressedLength & 0xff));
-            baseStream.WriteByte((byte) ((compressedLength >> 8) & 0xff));
-            baseStream.WriteByte((byte) ((compressedLength >> 16) & 0Xff));
-            baseStream.WriteByte(seq);
-            baseStream.WriteByte((byte) (uncompressedLength & 0xff));
-            baseStream.WriteByte((byte) ((uncompressedLength >> 8) & 0xff));
-            baseStream.WriteByte((byte) ((uncompressedLength >> 16) & 0Xff));
-
-            if (compressedBuffer == null)
-                baseStream.Write(cacheBuffer, 0, (int) cache.Length);
-            else
-            {
-                byte[] compressedBytes = compressedBuffer.GetBuffer();
-                baseStream.Write(compressedBytes, 0, (int) compressedBuffer.Length);
-            }
+            // Make space for length prefix (7 bytes) at the start of output
+            long dataLength = memStream.Length;
+            int bytesToWrite = (int)dataLength + 7;
+            memStream.SetLength(bytesToWrite);
+
+            byte[] buffer = memStream.GetBuffer();
+            Array.Copy(buffer, 0, buffer, 7, dataLength);
+
+            // Write length prefix
+            buffer[0] = (byte) (compressedLength & 0xff);
+            buffer[1] = (byte) ((compressedLength >> 8) & 0xff);
+            buffer[2] = (byte) ((compressedLength >> 16) & 0xff);
+            buffer[3] = seq;
+            buffer[4] = (byte) (uncompressedLength & 0xff);
+            buffer[5] = (byte) ((uncompressedLength >> 8) & 0xff);
+            buffer[6] = (byte) ((uncompressedLength >> 16) & 0xff);
 
+            baseStream.Write(buffer, 0, bytesToWrite);
             baseStream.Flush();
-
             cache.SetLength(0);
         }
 


Attachment: [text/bzr-bundle] bzr/vvaintroub@mysql.com-20100728140701-h2c5b02x6iwc0d1i.bundle
Thread
bzr commit into connector-net-6.1 branch (vvaintroub:834) Vladislav Vaintroub28 Jul