hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r355186 - in /jakarta/httpcomponents/trunk/http-core/src: java/org/apache/http/impl/ java/org/apache/http/impl/io/ java/org/apache/http/io/ test/org/apache/http/impl/
Date Thu, 08 Dec 2005 20:12:31 GMT
Author: olegk
Date: Thu Dec  8 12:12:15 2005
New Revision: 355186

URL: http://svn.apache.org/viewcvs?rev=355186&view=rev
Log:
Reuse the char array buffer in DefaultHttpClientConnection and DefaultHttpServerConnection
to reduce intermediate garbage

Modified:
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpServerConnection.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/io/AbstractHttpDataTransmitter.java
    jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/HttpDataTransmitter.java
    jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/impl/TestHttpDataReceiverAndTransmitter.java

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpClientConnection.java?rev=355186&r1=355185&r2=355186&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
Thu Dec  8 12:12:15 2005
@@ -48,6 +48,7 @@
 import org.apache.http.HttpVersion;
 import org.apache.http.NoHttpResponseException;
 import org.apache.http.ProtocolException;
+import org.apache.http.RequestLine;
 import org.apache.http.StatusLine;
 import org.apache.http.impl.entity.DefaultClientEntityWriter;
 import org.apache.http.impl.entity.DefaultEntityGenerator;
@@ -174,10 +175,11 @@
     
     protected void sendRequestLine(
             final HttpRequest request) throws HttpException, IOException {
-        String line = request.getRequestLine().toString();
-        this.datatransmitter.writeLine(line);
+        this.buffer.clear();
+        RequestLine.format(this.buffer, request.getRequestLine());
+        this.datatransmitter.writeLine(this.buffer);
         if (isWirelogEnabled()) {
-            wirelog(">> " + line + "[\\r][\\n]");
+            wirelog(">> " + this.buffer.toString() + "[\\r][\\n]");
         }
     }
 
@@ -185,13 +187,15 @@
             final HttpRequest request) throws HttpException, IOException {
         Header[] headers = request.getAllHeaders();
         for (int i = 0; i < headers.length; i++) {
-            String line = headers[i].toString();
-            this.datatransmitter.writeLine(line);
+            this.buffer.clear();
+            Header.format(this.buffer, headers[i]);
+            this.datatransmitter.writeLine(this.buffer);
             if (isWirelogEnabled()) {
-                wirelog(">> " + line + "[\\r][\\n]");
+                wirelog(">> " + this.buffer.toString() + "[\\r][\\n]");
             }
         }
-        this.datatransmitter.writeLine("");
+        this.buffer.clear();
+        this.datatransmitter.writeLine(this.buffer);
         if (isWirelogEnabled()) {
             wirelog(">> [\\r][\\n]");
         }

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpServerConnection.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpServerConnection.java?rev=355186&r1=355185&r2=355186&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpServerConnection.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/DefaultHttpServerConnection.java
Thu Dec  8 12:12:15 2005
@@ -43,6 +43,7 @@
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpServerConnection;
 import org.apache.http.RequestLine;
+import org.apache.http.StatusLine;
 import org.apache.http.impl.entity.DefaultEntityGenerator;
 import org.apache.http.impl.entity.DefaultServerEntityWriter;
 import org.apache.http.impl.entity.EntityGenerator;
@@ -156,10 +157,11 @@
     
     protected void sendResponseStatusLine(final HttpResponse response) 
             throws HttpException, IOException {
-        String line = response.getStatusLine().toString();
-        this.datatransmitter.writeLine(line);
+        this.buffer.clear();
+        StatusLine.format(this.buffer, response.getStatusLine());
+        this.datatransmitter.writeLine(this.buffer);
         if (isWirelogEnabled()) {
-            wirelog("<< " + line + "[\\r][\\n]");
+            wirelog("<< " + this.buffer.toString() + "[\\r][\\n]");
         }
     }
 
@@ -167,13 +169,15 @@
             throws HttpException, IOException {
         Header[] headers = response.getAllHeaders();
         for (int i = 0; i < headers.length; i++) {
-            String line = headers[i].toString();
-            this.datatransmitter.writeLine(line);
+            this.buffer.clear();
+            Header.format(this.buffer, headers[i]);
+            this.datatransmitter.writeLine(this.buffer);
             if (isWirelogEnabled()) {
-                wirelog("<< " + line + "[\\r][\\n]");
+                wirelog("<< " + this.buffer.toString() + "[\\r][\\n]");
             }
         }
-        this.datatransmitter.writeLine("");
+        this.buffer.clear();
+        this.datatransmitter.writeLine(this.buffer);
         if (isWirelogEnabled()) {
             wirelog("<< [\\r][\\n]");
         }

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/io/AbstractHttpDataTransmitter.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/io/AbstractHttpDataTransmitter.java?rev=355186&r1=355185&r2=355186&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/io/AbstractHttpDataTransmitter.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/impl/io/AbstractHttpDataTransmitter.java
Thu Dec  8 12:12:15 2005
@@ -32,6 +32,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 
+import org.apache.http.io.CharArrayBuffer;
 import org.apache.http.io.HttpDataTransmitter;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
@@ -118,6 +119,13 @@
         }
         write(s.getBytes(this.charset));
         write(CRLF);
+    }
+    
+    public void writeLine(final CharArrayBuffer buffer) throws IOException {
+        if (buffer == null) {
+            return;
+        }
+        writeLine(buffer.toString());
     }
     
     public void reset(final HttpParams params) {

Modified: jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/HttpDataTransmitter.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/HttpDataTransmitter.java?rev=355186&r1=355185&r2=355186&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/HttpDataTransmitter.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/java/org/apache/http/io/HttpDataTransmitter.java
Thu Dec  8 12:12:15 2005
@@ -54,6 +54,8 @@
     
     void writeLine(String s) throws IOException;
     
+    void writeLine(CharArrayBuffer buffer) throws IOException;
+    
     void flush() throws IOException;
     
 }

Modified: jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/impl/TestHttpDataReceiverAndTransmitter.java
URL: http://svn.apache.org/viewcvs/jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/impl/TestHttpDataReceiverAndTransmitter.java?rev=355186&r1=355185&r2=355186&view=diff
==============================================================================
--- jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/impl/TestHttpDataReceiverAndTransmitter.java
(original)
+++ jakarta/httpcomponents/trunk/http-core/src/test/org/apache/http/impl/TestHttpDataReceiverAndTransmitter.java
Thu Dec  8 12:12:15 2005
@@ -112,7 +112,7 @@
             transmitter.writeLine(teststrs[i]);
         }
         //this write operation should have no effect
-        transmitter.writeLine(null);
+        transmitter.writeLine((String)null);
         transmitter.flush();
         
         HttpDataReceiverMockup receiver = new HttpDataReceiverMockup(
@@ -202,7 +202,7 @@
             transmitter.writeLine(teststrs[i]);
         }
         //this write operation should have no effect
-        transmitter.writeLine(null);
+        transmitter.writeLine((String)null);
         transmitter.flush();
         
         HttpDataReceiverMockup receiver = new HttpDataReceiverMockup(



Mime
View raw message