This is an automated email from the ASF dual-hosted git repository.

jking pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git


The following commit(s) were added to refs/heads/master by this push:
     new 138a81d  THRIFT-4704: Streamline TDeserializer Implementation
138a81d is described below

commit 138a81d5b401b57ee4883879f94b10ba4f935453
Author: Beluga Behr <dam6...@gmail.com>
AuthorDate: Mon Dec 31 11:38:15 2018 -0500

    THRIFT-4704: Streamline TDeserializer Implementation
---
 lib/java/src/org/apache/thrift/TDeserializer.java | 59 ++++++++---------------
 1 file changed, 20 insertions(+), 39 deletions(-)

diff --git a/lib/java/src/org/apache/thrift/TDeserializer.java 
b/lib/java/src/org/apache/thrift/TDeserializer.java
index bf6c97c..d1d3966 100644
--- a/lib/java/src/org/apache/thrift/TDeserializer.java
+++ b/lib/java/src/org/apache/thrift/TDeserializer.java
@@ -251,48 +251,31 @@ public class TDeserializer {
     try {
       TField field = locateField(bytes, fieldIdPathFirst, fieldIdPathRest);
       if (field != null) {
-        // if this point is reached, iprot will be positioned at the start of 
the field.
-        switch(ttype){
+        if (ttype == field.type) {
+          // if this point is reached, iprot will be positioned at the start of
+          // the field
+          switch (ttype) {
           case TType.BOOL:
-            if (field.type == TType.BOOL){
-              return protocol_.readBool();
-            }
-            break;
+            return protocol_.readBool();
           case TType.BYTE:
-            if (field.type == TType.BYTE) {
-              return protocol_.readByte();
-            }
-            break;
+            return protocol_.readByte();
           case TType.DOUBLE:
-            if (field.type == TType.DOUBLE) {
-              return protocol_.readDouble();
-            }
-            break;
+            return protocol_.readDouble();
           case TType.I16:
-            if (field.type == TType.I16) {
-              return protocol_.readI16();
-            }
-            break;
+            return protocol_.readI16();
           case TType.I32:
-            if (field.type == TType.I32) {
-              return protocol_.readI32();
-            }
-            break;
+            return protocol_.readI32();
           case TType.I64:
-            if (field.type == TType.I64) {
-              return protocol_.readI64();
-            }
-            break;
+            return protocol_.readI64();
           case TType.STRING:
-            if (field.type == TType.STRING) {
-              return protocol_.readString();
-            }
-            break;
-          case 100: // hack to differentiate between string and binary
-            if (field.type == TType.STRING) {
-              return protocol_.readBinary();
-            }
-            break;
+            return protocol_.readString();
+          default:
+            return null;
+          }
+        }
+        // hack to differentiate between string and binary
+        if (ttype == 100 && field.type == TType.STRING) {
+          return protocol_.readBinary();
         }
       }
       return null;
@@ -307,11 +290,9 @@ public class TDeserializer {
   private TField locateField(byte[] bytes, TFieldIdEnum fieldIdPathFirst, 
TFieldIdEnum ... fieldIdPathRest) throws TException {
     trans_.reset(bytes);
 
-    TFieldIdEnum[] fieldIdPath= new TFieldIdEnum[fieldIdPathRest.length + 1];
+    TFieldIdEnum[] fieldIdPath = new TFieldIdEnum[fieldIdPathRest.length + 1];
     fieldIdPath[0] = fieldIdPathFirst;
-    for (int i = 0; i < fieldIdPathRest.length; i++){
-      fieldIdPath[i + 1] = fieldIdPathRest[i];
-    }
+    System.arraycopy(fieldIdPathRest, 0, fieldIdPath, 1, 
fieldIdPathRest.length);
 
     // index into field ID path being currently searched for
     int curPathIndex = 0;

Reply via email to