remm 2003/09/12 05:58:53
Modified: util/java/org/apache/tomcat/util/buf ByteChunk.java
Log:
- Refactor byte chunk buffering so that the written data fits inside the limit.
The number of byte copies is similar to what it was before.
Revision Changes Path
1.15 +19 -28
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/ByteChunk.java
Index: ByteChunk.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/ByteChunk.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ByteChunk.java 2 Sep 2003 21:34:38 -0000 1.14
+++ ByteChunk.java 12 Sep 2003 12:58:53 -0000 1.15
@@ -338,34 +338,25 @@
// the buffer is already at ( or bigger than ) limit
- // Optimization:
- // If len-avail < length ( i.e. after we fill the buffer with
- // what we can, the remaining will fit in the buffer ) we'll just
- // copy the first part, flush, then copy the second part - 1 write
- // and still have some space for more. We'll still have 2 writes, but
- // we write more on the first.
-
- if( len + end < 2 * limit ) {
- /* If the request length exceeds the size of the output buffer,
- flush the output buffer and then write the data directly.
- We can't avoid 2 writes, but we can write more on the second
- */
- int avail=limit-end;
- System.arraycopy(src, off, buff, end, avail);
- end += avail;
-
- flushBuffer();
-
- System.arraycopy(src, off+avail, buff, end, len - avail);
- end+= len - avail;
-
- } else { // len > buf.length + avail
- // long write - flush the buffer and write the rest
- // directly from source
- flushBuffer();
-
- out.realWriteBytes( src, off, len );
- }
+ // We chunk the data into slices fitting in the buffer limit, although
+ // if the data is written directly if it doesn't fit
+
+ int avail=limit-end;
+ System.arraycopy(src, off, buff, end, avail);
+ end += avail;
+
+ flushBuffer();
+
+ int remain = len - avail;
+
+ while (remain > (limit - end)) {
+ out.realWriteBytes( src, (off + len) - remain, limit - end );
+ remain = remain - (limit - end);
+ }
+
+ System.arraycopy(src, (off + len) - remain, buff, end, remain);
+ end += remain;
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]