You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/04/26 10:51:04 UTC

[GitHub] beiwei30 closed pull request #1705: [Dubbo-1659] Optimize_hessian_desr_performance

beiwei30 closed pull request #1705: [Dubbo-1659] Optimize_hessian_desr_performance
URL: https://github.com/apache/incubator-dubbo/pull/1705
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/hessian-lite/src/main/java/com/alibaba/com/caucho/hessian/io/Hessian2Input.java b/hessian-lite/src/main/java/com/alibaba/com/caucho/hessian/io/Hessian2Input.java
index 268c6993d8..85d18a9700 100644
--- a/hessian-lite/src/main/java/com/alibaba/com/caucho/hessian/io/Hessian2Input.java
+++ b/hessian-lite/src/main/java/com/alibaba/com/caucho/hessian/io/Hessian2Input.java
@@ -119,7 +119,7 @@
     private Reader _chunkReader;
     private InputStream _chunkInputStream;
     private Throwable _replyFault;
-    private StringBuffer _sbuf = new StringBuffer();
+    private StringBuilder _sbuf = new StringBuilder();
     // true if this is the last chunk
     private boolean _isLastChunk;
     // the chunk length
@@ -2493,11 +2493,9 @@ public Object readObject(List<Class<?>> expectedTypes) throws IOException {
                 _isLastChunk = tag == 'S';
                 _chunkLength = (read() << 8) + read();
 
-                int data;
                 _sbuf.setLength(0);
 
-                while ((data = parseChar()) >= 0)
-                    _sbuf.append((char) data);
+                parseString(_sbuf);
 
                 return _sbuf.toString();
             }
@@ -2538,11 +2536,9 @@ public Object readObject(List<Class<?>> expectedTypes) throws IOException {
                 _isLastChunk = true;
                 _chunkLength = tag - 0x00;
 
-                int data;
                 _sbuf.setLength(0);
 
-                while ((data = parseChar()) >= 0)
-                    _sbuf.append((char) data);
+                parseString(_sbuf);
 
                 return _sbuf.toString();
             }
@@ -2556,9 +2552,7 @@ public Object readObject(List<Class<?>> expectedTypes) throws IOException {
 
                 _sbuf.setLength(0);
 
-                int ch;
-                while ((ch = parseChar()) >= 0)
-                    _sbuf.append((char) ch);
+                parseString(_sbuf);
 
                 return _sbuf.toString();
             }
@@ -2772,6 +2766,23 @@ public Object readObject(List<Class<?>> expectedTypes) throws IOException {
         }
     }
 
+    private void parseString(StringBuilder sbuf)
+            throws IOException {
+        while (true) {
+            if (_chunkLength <= 0) {
+                if (!parseChunkLength())
+                    return;
+            }
+
+            int length = _chunkLength;
+            _chunkLength = 0;
+
+            while (length-- > 0) {
+                sbuf.append((char) parseUTF8Char());
+            }
+        }
+    }
+
     /**
      * Reads an object definition:
      * <p>
@@ -3157,80 +3168,86 @@ private double parseDouble()
         throw new UnsupportedOperationException();
     }
 
-    /**
-     * Reads a character from the underlying stream.
-     */
-    private int parseChar()
+    private boolean parseChunkLength()
             throws IOException {
-        while (_chunkLength <= 0) {
-            if (_isLastChunk)
-                return -1;
+        if (_isLastChunk)
+            return false;
 
-            int code = _offset < _length ? (_buffer[_offset++] & 0xff) : read();
+        int code = _offset < _length ? (_buffer[_offset++] & 0xff) : read();
 
-            switch (code) {
-                case BC_STRING_CHUNK:
-                    _isLastChunk = false;
+        switch (code) {
+            case BC_STRING_CHUNK:
+                _isLastChunk = false;
 
-                    _chunkLength = (read() << 8) + read();
-                    break;
+                _chunkLength = (read() << 8) + read();
+                break;
 
-                case 'S':
-                    _isLastChunk = true;
+            case 'S':
+                _isLastChunk = true;
 
-                    _chunkLength = (read() << 8) + read();
-                    break;
+                _chunkLength = (read() << 8) + read();
+                break;
 
-                case 0x00:
-                case 0x01:
-                case 0x02:
-                case 0x03:
-                case 0x04:
-                case 0x05:
-                case 0x06:
-                case 0x07:
-                case 0x08:
-                case 0x09:
-                case 0x0a:
-                case 0x0b:
-                case 0x0c:
-                case 0x0d:
-                case 0x0e:
-                case 0x0f:
+            case 0x00:
+            case 0x01:
+            case 0x02:
+            case 0x03:
+            case 0x04:
+            case 0x05:
+            case 0x06:
+            case 0x07:
+            case 0x08:
+            case 0x09:
+            case 0x0a:
+            case 0x0b:
+            case 0x0c:
+            case 0x0d:
+            case 0x0e:
+            case 0x0f:
 
-                case 0x10:
-                case 0x11:
-                case 0x12:
-                case 0x13:
-                case 0x14:
-                case 0x15:
-                case 0x16:
-                case 0x17:
-                case 0x18:
-                case 0x19:
-                case 0x1a:
-                case 0x1b:
-                case 0x1c:
-                case 0x1d:
-                case 0x1e:
-                case 0x1f:
-                    _isLastChunk = true;
-                    _chunkLength = code - 0x00;
-                    break;
+            case 0x10:
+            case 0x11:
+            case 0x12:
+            case 0x13:
+            case 0x14:
+            case 0x15:
+            case 0x16:
+            case 0x17:
+            case 0x18:
+            case 0x19:
+            case 0x1a:
+            case 0x1b:
+            case 0x1c:
+            case 0x1d:
+            case 0x1e:
+            case 0x1f:
+                _isLastChunk = true;
+                _chunkLength = code - 0x00;
+                break;
 
-                // qian.lei 2010-7-21
-                case 0x30:
-                case 0x31:
-                case 0x32:
-                case 0x33:
-                    _isLastChunk = true;
-                    _chunkLength = ((code - 0x30) << 8) + read();
-                    break;
+            case 0x30:
+            case 0x31:
+            case 0x32:
+            case 0x33:
+                _isLastChunk = true;
+                _chunkLength = (code - 0x30) * 256 + read();
+                break;
 
-                default:
-                    throw expect("string", code);
-            }
+            default:
+                throw expect("string", code);
+        }
+
+        return true;
+    }
 
+    /**
+     * Reads a character from the underlying stream.
+     */
+    private int parseChar()
+            throws IOException {
+        while (_chunkLength <= 0) {
+            if (!parseChunkLength())
+                return -1;
         }
 
         _chunkLength--;


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org