You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2005/10/23 20:22:09 UTC
svn commit: r327829 - in /jakarta/httpclient/trunk/http-nio: ./
src/java/org/apache/http/nio/NIOHttpDataReceiver.java
Author: olegk
Date: Sun Oct 23 11:22:01 2005
New Revision: 327829
URL: http://svn.apache.org/viewcvs?rev=327829&view=rev
Log:
Another round of performance optimization
* Abstract HTTP data receiver extended with a method to read HTTP line into a char buffer. This method is intended to reduce the amount of garbage generated when parsing HTTP lines
* Abstract HTTP data receiver uses byte to char cast when converting raw bytes to US-ASCII chars
Modified:
jakarta/httpclient/trunk/http-nio/ (props changed)
jakarta/httpclient/trunk/http-nio/src/java/org/apache/http/nio/NIOHttpDataReceiver.java
Propchange: jakarta/httpclient/trunk/http-nio/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Oct 23 11:22:01 2005
@@ -0,0 +1,4 @@
+
+bin
+.classpath
+.project
Modified: jakarta/httpclient/trunk/http-nio/src/java/org/apache/http/nio/NIOHttpDataReceiver.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-nio/src/java/org/apache/http/nio/NIOHttpDataReceiver.java?rev=327829&r1=327828&r2=327829&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-nio/src/java/org/apache/http/nio/NIOHttpDataReceiver.java (original)
+++ jakarta/httpclient/trunk/http-nio/src/java/org/apache/http/nio/NIOHttpDataReceiver.java Sun Oct 23 11:22:01 2005
@@ -146,11 +146,13 @@
return -1;
}
- public String readLine() throws IOException {
+ public int readLine(final CharArrayBuffer charbuffer) throws IOException {
+ if (charbuffer == null) {
+ throw new IllegalArgumentException("Char array buffer may not be null");
+ }
int noRead = 0;
this.chbuffer.clear();
this.chardecoder.reset();
- CharArrayBuffer line = new CharArrayBuffer(128);
boolean retry = true;
while (retry) {
// attempt to find end of line (LF)
@@ -166,7 +168,7 @@
this.buffer, this.chbuffer, true);
if (result.isOverflow()) {
this.chbuffer.flip();
- line.append(this.chbuffer.array(),
+ charbuffer.append(this.chbuffer.array(),
this.chbuffer.position(), this.chbuffer.remaining());
this.chbuffer.clear();
}
@@ -192,7 +194,7 @@
// append the decoded content to the line buffer
this.chbuffer.flip();
if (this.chbuffer.hasRemaining()) {
- line.append(this.chbuffer.array(),
+ charbuffer.append(this.chbuffer.array(),
this.chbuffer.position(), this.chbuffer.remaining());
}
this.chbuffer.clear();
@@ -202,29 +204,39 @@
this.chbuffer.flip();
// append the decoded content to the line buffer
if (this.chbuffer.hasRemaining()) {
- line.append(this.chbuffer.array(),
+ charbuffer.append(this.chbuffer.array(),
this.chbuffer.position(), this.chbuffer.remaining());
}
- if (noRead == -1 && line.length() == 0) {
+ if (noRead == -1 && charbuffer.length() == 0) {
// indicate the end of stream
- return null;
+ return -1;
}
// discard LF if found
- int l = line.length();
+ int l = charbuffer.length();
if (l > 0) {
- if (line.charAt(l - 1) == LF) {
+ if (charbuffer.charAt(l - 1) == LF) {
l--;
- line.setLength(l);
+ charbuffer.setLength(l);
}
// discard CR if found
if (l > 0) {
- if (line.charAt(l - 1) == CR) {
+ if (charbuffer.charAt(l - 1) == CR) {
l--;
- line.setLength(l);
+ charbuffer.setLength(l);
}
}
}
- return line.toString();
+ return l;
}
+ public String readLine() throws IOException {
+ CharArrayBuffer charbuffer = new CharArrayBuffer(64);
+ int l = readLine(charbuffer);
+ if (l != -1) {
+ return charbuffer.toString();
+ } else {
+ return null;
+ }
+ }
+
}