2006-03-27 Joshua Tauberer <tauberer@for.net>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 7 Apr 2006 22:27:56 +0000 (22:27 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Fri, 7 Apr 2006 22:27:56 +0000 (22:27 -0000)
* HttpWriter.cs: Avoid creation of a byte[] on each Write()
  by reusing and resizing a private array.

svn path=/trunk/mcs/; revision=59234

mcs/class/System.Web/System.Web/ChangeLog
mcs/class/System.Web/System.Web/HttpWriter.cs

index d1bf2c1336c91e308c7374421f406f341aefdb8b..c0c1d33588043a73fd2e30455622a4304adb9b15 100644 (file)
@@ -1,3 +1,8 @@
+2006-03-27 Joshua Tauberer <tauberer@for.net>
+
+       * HttpWriter.cs: Avoid creation of a byte[] on each Write()
+         by reusing and resizing a private array.
+
 2006-04-07 Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * HttpRequest.cs: the field content_length can be < 0 and then we try to
index 5537f85b7dfeaba4ba06befdf09f657fee17e8db..1632c822fe01f93871c0ad0243369347a7ff2d18 100644 (file)
@@ -42,6 +42,7 @@ namespace System.Web {
                HttpResponseStream output_stream;
                HttpResponse response;
                Encoding encoding;
+               byte [] bytebuffer = new byte [256];
 
                internal HttpWriter (HttpResponse response)
                {
@@ -97,23 +98,20 @@ namespace System.Web {
                
                public override void Write (string s)
                {
-                       if (s == null)
-                               return;
-                       
-                       byte [] xx = encoding.GetBytes (s);
-
-                       output_stream.Write (xx, 0, xx.Length);
-                       
-                       if (response.buffer)
-                               return;
-
-                       response.Flush ();
+                       WriteString (s, 0, s.Length);
                }
                
                public override void Write (char [] buffer, int index, int count)
                {
-                       byte [] xx = encoding.GetBytes (buffer, index, count);
-                       output_stream.Write (xx, 0, xx.Length);
+                       /*byte [] xx = encoding.GetBytes (buffer, index, count);
+                       output_stream.Write (xx, 0, xx.Length);*/
+                       
+                       int length = encoding.GetByteCount (buffer, index, count);
+                       if (length > bytebuffer.Length)
+                               bytebuffer = new byte [length << 1];
+
+                       encoding.GetBytes (buffer, index, count, bytebuffer, 0);
+                       output_stream.Write (bytebuffer, 0, length);
 
                        if (response.buffer)
                                return;
@@ -135,12 +133,23 @@ namespace System.Web {
 
                public void WriteString (string s, int index, int count)
                {
-                       char [] a = s.ToCharArray (index, count);
+                       if (s == null)
+                               return;
 
-                       byte [] xx = encoding.GetBytes (a, 0, count);
-                       
-                       output_stream.Write (xx, 0, xx.Length);
+                       int length;
+                       if (index == 0 && count == s.Length) {
+                               length = encoding.GetByteCount (s); 
+                       } else {
+                               char [] chars = s.ToCharArray (index, count);
+                               length = encoding.GetByteCount (chars);
+                       }
 
+                       if (length > bytebuffer.Length)
+                               bytebuffer = new byte [length << 1];
+
+                       encoding.GetBytes (s, index, count, bytebuffer, 0);
+                       output_stream.Write (bytebuffer, 0, length);
+                       
                        if (response.buffer)
                                return;