From: remm Date: Sat, 10 Feb 2007 01:32:10 +0000 (+0000) Subject: - Set of minor optimizations. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=fb9f25b270cdccd37f6438763e863713e4f778fb;p=tomcat7.0 - Set of minor optimizations. - Use getLength() less often. - Submitted by Arvind Srinivasan. git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@505604 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/connector/CoyoteAdapter.java b/java/org/apache/catalina/connector/CoyoteAdapter.java index 05ef81aa3..e6b35a20d 100644 --- a/java/org/apache/catalina/connector/CoyoteAdapter.java +++ b/java/org/apache/catalina/connector/CoyoteAdapter.java @@ -505,8 +505,9 @@ public class CoyoteAdapter throws Exception { ByteChunk bc = uri.getByteChunk(); + int length = bc.getLength(); CharChunk cc = uri.getCharChunk(); - cc.allocate(bc.getLength(), -1); + cc.allocate(length, -1); String enc = connector.getURIEncoding(); if (enc != null) { @@ -540,10 +541,10 @@ public class CoyoteAdapter byte[] bbuf = bc.getBuffer(); char[] cbuf = cc.getBuffer(); int start = bc.getStart(); - for (int i = 0; i < bc.getLength(); i++) { + for (int i = 0; i < length; i++) { cbuf[i] = (char) (bbuf[i + start] & 0xff); } - uri.setChars(cbuf, 0, bc.getLength()); + uri.setChars(cbuf, 0, length); } @@ -559,16 +560,17 @@ public class CoyoteAdapter ByteChunk bc = mb.getByteChunk(); CharChunk cc = mb.getCharChunk(); - cc.allocate(bc.getLength(), -1); + int length = bc.getLength(); + cc.allocate(length, -1); // Default encoding: fast conversion byte[] bbuf = bc.getBuffer(); char[] cbuf = cc.getBuffer(); int start = bc.getStart(); - for (int i = 0; i < bc.getLength(); i++) { + for (int i = 0; i < length; i++) { cbuf[i] = (char) (bbuf[i + start] & 0xff); } - mb.setChars(cbuf, 0, bc.getLength()); + mb.setChars(cbuf, 0, length); } diff --git a/java/org/apache/coyote/ajp/AjpAprProcessor.java b/java/org/apache/coyote/ajp/AjpAprProcessor.java index 2422e8cd4..693d65628 100644 --- a/java/org/apache/coyote/ajp/AjpAprProcessor.java +++ b/java/org/apache/coyote/ajp/AjpAprProcessor.java @@ -598,8 +598,9 @@ public class AjpAprProcessor implements ActionHook { // Set the given bytes as the content ByteChunk bc = (ByteChunk) param; - bodyBytes.setBytes(bc.getBytes(), bc.getStart(), bc.getLength()); - request.setContentLength(bc.getLength()); + int length = bc.getLength(); + bodyBytes.setBytes(bc.getBytes(), bc.getStart(), length); + request.setContentLength(length); first = false; empty = false; replay = true; diff --git a/java/org/apache/coyote/ajp/AjpProcessor.java b/java/org/apache/coyote/ajp/AjpProcessor.java index 384817052..5f4a3a3f0 100644 --- a/java/org/apache/coyote/ajp/AjpProcessor.java +++ b/java/org/apache/coyote/ajp/AjpProcessor.java @@ -586,8 +586,9 @@ public class AjpProcessor implements ActionHook { // Set the given bytes as the content ByteChunk bc = (ByteChunk) param; - bodyBytes.setBytes(bc.getBytes(), bc.getStart(), bc.getLength()); - request.setContentLength(bc.getLength()); + int length = bc.getLength(); + bodyBytes.setBytes(bc.getBytes(), bc.getStart(), length); + request.setContentLength(length); first = false; empty = false; replay = true; diff --git a/java/org/apache/coyote/http11/InternalAprOutputBuffer.java b/java/org/apache/coyote/http11/InternalAprOutputBuffer.java index b217578b4..926be3b03 100644 --- a/java/org/apache/coyote/http11/InternalAprOutputBuffer.java +++ b/java/org/apache/coyote/http11/InternalAprOutputBuffer.java @@ -585,9 +585,9 @@ public class InternalAprOutputBuffer protected void write(ByteChunk bc) { // Writing the byte chunk to the output buffer - System.arraycopy(bc.getBytes(), bc.getStart(), buf, pos, - bc.getLength()); - pos = pos + bc.getLength(); + int length = bc.getLength(); + System.arraycopy(bc.getBytes(), bc.getStart(), buf, pos, length); + pos = pos + length; } diff --git a/java/org/apache/coyote/http11/InternalNioOutputBuffer.java b/java/org/apache/coyote/http11/InternalNioOutputBuffer.java index 1366312e4..dae3e5245 100644 --- a/java/org/apache/coyote/http11/InternalNioOutputBuffer.java +++ b/java/org/apache/coyote/http11/InternalNioOutputBuffer.java @@ -644,9 +644,9 @@ public class InternalNioOutputBuffer protected void write(ByteChunk bc) { // Writing the byte chunk to the output buffer - System.arraycopy(bc.getBytes(), bc.getStart(), buf, pos, - bc.getLength()); - pos = pos + bc.getLength(); + int length = bc.getLength(); + System.arraycopy(bc.getBytes(), bc.getStart(), buf, pos, length); + pos = pos + length; } diff --git a/java/org/apache/coyote/http11/InternalOutputBuffer.java b/java/org/apache/coyote/http11/InternalOutputBuffer.java index 1df2fc6fe..4445f2305 100644 --- a/java/org/apache/coyote/http11/InternalOutputBuffer.java +++ b/java/org/apache/coyote/http11/InternalOutputBuffer.java @@ -631,9 +631,9 @@ public class InternalOutputBuffer protected void write(ByteChunk bc) { // Writing the byte chunk to the output buffer - System.arraycopy(bc.getBytes(), bc.getStart(), buf, pos, - bc.getLength()); - pos = pos + bc.getLength(); + int length = bc.getLength(); + System.arraycopy(bc.getBytes(), bc.getStart(), buf, pos, length); + pos = pos + length; } @@ -756,14 +756,15 @@ public class InternalOutputBuffer public int doWrite(ByteChunk chunk, Response res) throws IOException { + int length = chunk.getLength(); if (useSocketBuffer) { socketBuffer.append(chunk.getBuffer(), chunk.getStart(), - chunk.getLength()); + length); } else { outputStream.write(chunk.getBuffer(), chunk.getStart(), - chunk.getLength()); + length); } - return chunk.getLength(); + return length; } diff --git a/java/org/apache/jk/common/MsgAjp.java b/java/org/apache/jk/common/MsgAjp.java index 642b270f4..f9fcf3cd2 100644 --- a/java/org/apache/jk/common/MsgAjp.java +++ b/java/org/apache/jk/common/MsgAjp.java @@ -165,8 +165,9 @@ public class MsgAjp extends Msg { byte[] bytes = bc.getBytes(); int start=bc.getStart(); - appendInt( bc.getLength() ); - cpBytes(bytes, start, bc.getLength()); + int length = bc.getLength(); + appendInt( length ); + cpBytes(bytes, start, length); appendByte(0); } diff --git a/java/org/apache/tomcat/util/http/Parameters.java b/java/org/apache/tomcat/util/http/Parameters.java index 6c04445fd..03f59b800 100644 --- a/java/org/apache/tomcat/util/http/Parameters.java +++ b/java/org/apache/tomcat/util/http/Parameters.java @@ -414,15 +414,16 @@ public final class Parameters extends MultiMap { result = bc.toString(); } else { CharChunk cc = tmpNameC; - cc.allocate(bc.getLength(), -1); + int length = bc.getLength(); + cc.allocate(length, -1); // Default encoding: fast conversion byte[] bbuf = bc.getBuffer(); char[] cbuf = cc.getBuffer(); int start = bc.getStart(); - for (int i = 0; i < bc.getLength(); i++) { + for (int i = 0; i < length; i++) { cbuf[i] = (char) (bbuf[i + start] & 0xff); } - cc.setChars(cbuf, 0, bc.getLength()); + cc.setChars(cbuf, 0, length); result = cc.toString(); cc.recycle(); }