THRIFT-4704: Streamline TDeserializer Implementation
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 @@
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 @@
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;