jonahaapala commented on code in PR #3173: URL: https://github.com/apache/thrift/pull/3173#discussion_r2178725034
########## lib/java/src/main/java/org/apache/thrift/protocol/TCompactProtocol.java: ########## @@ -944,6 +923,43 @@ public int getMinSerializedSize(byte type) throws TTransportException { // ----------------------------------------------------------------- // Additional methods to improve performance. + @Override + public int readFieldBeginData() throws TException { + byte type = readByte(); + + // if it's a stop, then we can return immediately, as the struct is over. + if (type == TType.STOP) { + return TFieldData.encode(type); + } + + return TFieldData.encode(getTType((byte) (type & 0x0f)), readFieldId(type)); + } + + // Only makes sense to be called by readFieldBegin and readFieldBeginData + private short readFieldId(byte type) throws TException { + short fieldId; + + // mask off the 4 MSB of the type header. it could contain a field id delta. + short modifier = (short) ((type & 0xf0) >> 4); + if (modifier == 0) { + // not a delta. look ahead for the zigzag varint field id. + fieldId = readI16(); + } else { + // has a delta. add the delta to the last read field id. + fieldId = (short) (lastFieldId_ + modifier); + } + + // if this happens to be a boolean field, the value is encoded in the type + if (isBoolType(type)) { + // save the boolean value in a special instance variable. + boolValue_ = (byte) (type & 0x0f) == Types.BOOLEAN_TRUE ? Boolean.TRUE : Boolean.FALSE; + } + + // push the new field onto the field stack so we can keep the deltas going. + lastFieldId_ = fieldId; + return fieldId; + } Review Comment: Just a copy of the existing code minus the TField allocation. But this should be logically equivalent. <img width="1432" alt="image" src="https://github.com/user-attachments/assets/7911d383-8019-44bc-8a27-627738378990" /> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@thrift.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org