- Set of minor optimizations.
authorremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 10 Feb 2007 01:32:10 +0000 (01:32 +0000)
committerremm <remm@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 10 Feb 2007 01:32:10 +0000 (01:32 +0000)
- 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

java/org/apache/catalina/connector/CoyoteAdapter.java
java/org/apache/coyote/ajp/AjpAprProcessor.java
java/org/apache/coyote/ajp/AjpProcessor.java
java/org/apache/coyote/http11/InternalAprOutputBuffer.java
java/org/apache/coyote/http11/InternalNioOutputBuffer.java
java/org/apache/coyote/http11/InternalOutputBuffer.java
java/org/apache/jk/common/MsgAjp.java
java/org/apache/tomcat/util/http/Parameters.java

index 05ef81a..e6b35a2 100644 (file)
@@ -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);
 
     }
 
index 2422e8c..693d656 100644 (file)
@@ -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;
index 3848170..5f4a3a3 100644 (file)
@@ -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;
index b217578..926be3b 100644 (file)
@@ -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;
 
     }
 
index 1366312..dae3e52 100644 (file)
@@ -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;
 
     }
 
index 1df2fc6..4445f23 100644 (file)
@@ -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;
 
         }
 
index 642b270..f9fcf3c 100644 (file)
@@ -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);
     }
 
index 6c04445..03f59b8 100644 (file)
@@ -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();
         }